I am experiencing the following problem while using acts_as_ferret.
My user has many posts, but the association between the two models is
rather complex, so I had to go with:
class User < ActiveRecord::Base has_many :posts, :finder_sql => "select * from posts blah blah
class Post < ActiveRecord::Base acts_as_ferret :fields => [:title, :content] end
Now, in the console the following will work as expected:
>> u = User.find(:first) >> u.posts >> Post.find_by_contents "blah"
But the following fails:
>> u.posts.find_by_contents "blah"
The log shows that the generated SQL is wrong:
SELECT * FROM `posts` WHERE (select * from posts blah blah blah) AND (posts.id in ('8','5'))
Please note that the WHERE clause in parens is really my entire
:finder_sql. I have not looked into aaf’s code, but it looks as though
it was unable to recognize that my association is completely defined
within :finder_sql, treated it as if it was just a set of :conditions,
and added a SELECT at the beginning.
Am I doing something wrong? Or, is there a workaround?
Thank you all in advance!