开发者

I'm getting "undefined method `abstract_class?' for Object:Class" for count_by_sql

I'm getting the error: undefined method 'abstract_class开发者_StackOverflow社区?' for Object:Class

on a count_by_sql as below:

my_count = ActiveRecord::Base.count_by_sql(["SELECT widgets FROM wodgets WHERE colour = ? LIMIT 1", my_favourite_colour])

I've just been upgrading from Rails 2.2.2 to 2.3.4 and it used to work before.


ActiveRecord's count_by_sql calls some deeper ActiveRecord::Base magic that assumes you are an actual ActiveRecord (ie something that inherits from AR, not AR itself) and thus tries to call an internal method called abstract_class? that would normally return the class name (eg Order or Product).

You can get around this by using an actual AR object (it doesn't matter which one) eg:

my_count = MyWidget.count_by_sql(["SELECT widgets FROM wodgets WHERE colour = ? LIMIT 1", my_favourite_colour])
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜