I was under the impression that the custom_finder
option in ActiveRecord meant that you got association extensions like .where
and .order
for free, for instance:
class Dog < ActiveRecord::Base
has_many :fleas, class_name: 'Flea',
finder_sql: "select fleas.* from fleas where pet_type = 'dog'"
end
granted this is not a great example as the 'finder_sql' is so trivial however it illustrates the point.
Generated SQL
I would expect the following
@dog = Dog.find(5)
@dog.fleas.where('num_legs > 2')
to generate
"select fleas.* from fleas where pet_type = 'dog' AND num_legs > 2
i.e. custom finder_sql + where clause
however what it actually generates is
"SELECT "base_posts".* FROM "fleas" WHERE "fleas"."dog_id" = 5 AND (num_legs > 2)
i.e. it completely ignores the custom finder_sql
and tries to join the fleas to the current dog.
If the custom finder_sql
doesn't cause the association extensions to respect it then what's the point in it - it could just be a method on the object...