On Thu, May 10, 2007 at 12:48:15PM +0200, Allen Young wrote:
> Jens Kraemer wrote:
> > On Thu, May 10, 2007 at 12:21:51PM +0200, Allen Young wrote:
> >> Allen Young wrote:
> >> Another question. What if resistance attribute is not in the materials
> >> table but in some other table which has a one-to-one relationship with
> >> materials table?
> >
> > define a method that retrieves the value and add the method's name as a
> > field's name to your call to acts_as_ferret. You might want to search
> > the list for 'indexed method' for an example of this.
> >
> There are about 100 attributes reside in several different tables. That
> means I need to define all this methods manually?
that depends - some metaprogramming might help make it a less daunting
task.
i.e.
class OtherClass
# define which fields you want to have indexed and how:
def ferret_fields
{ :field1 => { :store => :yes }, ... }
end
end
class MyModel
# collect field list for aaf
ferret_fields = { :name => {}, ... }
ferret_fields.update! OtherClass.ferret_fields
acts_as_ferret :fields => ferret_fields
# define getters
OtherClass.ferret_fields.keys.each do |field|
define_method :"ferret_#{field}" do
other_object.send(field)
end
end
end
you can also join various (textual) attributes together and let them
form a single field in the index where this is appropriate.
Indexing data from a lot of relationships is not trivial when it comes
to updating the index - whenever some record changes it's parent
object(s) (that acts as the root and goes into the Ferret index first)
has to be re-indexed.
Jens
--
Jens Krämer
webit! Gesellschaft für neue Medien mbH
Schnorrstraße 76 | 01069 Dresden
Telefon +49 351 46766-0 | Telefax +49 351 46766-66
[EMAIL PROTECTED] | www.webit.de
Amtsgericht Dresden | HRB 15422
GF Sven Haubold, Hagen Malessa
_______________________________________________
Ferret-talk mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ferret-talk