Can acts_as_ferret search only one of the inherit models in the
hierarchy of STI models? Say you have Contents, with types articles and
comments. I know that you do Contents.find_by_contents, but can you
also create indexed for Comment and Articles?
Though you could make it more generic by simply asking
“self.descends_from_active_record?” which is how rails decides if it
should
scope your “find” query for STI models. You can check out “base.rb” in
activerecord to see that.
I do believe that eventually AAF will scope queries for STI as I see a
TODO
in the source about it but Jens would be a better person to comment on
that.
One last note, if you are using Rails 1.1.6 or earlier and plan on using
something liked CachedModel (an abstract class that sits between
ActiveRecord::Base and the base of your STI model) please see my email
“Strange indexing issues with CachedModel, STI, and AAF” as Rails 1.1.6
does
not properly scope queries for STI that have an abstract_class parent.
Hope that helps,
Curtis
----- Original Message -----
From: “Miguel” [email protected]
To: [email protected]
Sent: Monday, November 20, 2006 8:15 PM
Subject: [Ferret-talk] acts_as_ferret with STI models
Ahhh… sorry about that. I redefined the field name for my STI because
“type” causes way to many problems.
class YourModel < ActiveRecord::Base
… code …
def inheritance_column
‘role’
end
end
You may come up with a better column name than that but I recommend
redefining it because you can’t do record.type without getting
warnings/errors (it caused problems elsewhere for me as well). Currently
AAF
does not scope queries for you (to my knowledge).
Hope that clears up the confusion I may have caused you,
Curtis
----- Original Message -----
From: “Miguel” [email protected]
To: [email protected]
Sent: Monday, November 20, 2006 10:38 PM
Subject: Re: [Ferret-talk] acts_as_ferret with STI models
On Mon, Nov 20, 2006 at 09:34:54PM -0500, Curtis Hatter wrote:
scope your “find” query for STI models. You can check out “base.rb” in
activerecord to see that.
I do believe that eventually AAF will scope queries for STI as I see a TODO
in the source about it but Jens would be a better person to comment on that.
AAF does no scoping for searches on an STI model, but as AAF uses
activerecord to retrieve the results delivered by find_by_contents, the
usual Rails scoping will take place, so you’ll get only instances of the
class you called find_by_contents on.
However the :limit and :offset options of find_by_contents become quite
useless since they will be applied to the (unscoped) result set from
ferret, and the scoping will only take place later when retrieving the
actual records from the db.
So scoping the ferret query is a good idea, and it should be possible to
integrate that into aaf once I find the time do make a new release…
cheers,
Jens
–
webit! Gesellschaft für neue Medien mbH www.webit.de
Dipl.-Wirtschaftsingenieur Jens Krämer [email protected]
Schnorrstraße 76 Tel +49 351 46766 0
D-01069 Dresden Fax +49 351 46766 66