I am trying to create a special active record assocation where I use a
class instance method inside the association. Is this possible to do?
Example:
Person
{
id : integer
name : string
age : integer
}
Pet
{
id : integer
name : string
species : string
age : integer
person_id : integer
}
class Person < ActiveRecord::Base
has_many_friends :pets
has_many :pets_older_than_self,
:class_name => “Pet”
:conditions => “age = #{self.age}”
end
Can I use the person’s age in the condition? I would think since the
generated sql will use the condition that the pet’s person id = the id
of the current person, it could also use other instance methods or
variables. However I can’t seem to get this to work.
Thank you for any help you can provide.
Chris