views:

23

answers:

1

I'm getting the error: "undefined method `abstract_class?' 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.

+1  A: 

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 in 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])
Taryn East