Hi,
I’ve tried to trim this example down to the minimum. Even though it
looks
complicated it is probably a fairly basic question about how
associations
and :include work. I want to do a find that is similar to the example
below.
The find statement doesn’t work because AttributeValue doesn’t have a
direct
association with Product: Product is one step further up the chain of
models. Can I somehow write the find statement without resorting to
:joins,
raw SQL or looping through the results to make some checks?
Thanks,
Peter
Class Product < ActiveRecord::Base
has_and_belongs_to_many :attributes
end
Class Attribute < ActiveRecord::Base
#not all attributes will be associated with a product
has_and_belongs_to_many :products
has_many :attribute_values
end
Class AttributeValue < ActiveRecord::Base
belongs_to :attribute
cannot create a belongs_to association with Variation
end
Class Variation < ActiveRecord::Base
has_many :attribute_values
belongs_to :product
def distinguishing_attribute_values
AttributeValue.find(:all, :include=>[:attribute, :products],
:conditions=>"
product.id=’#{product.id}’");
end
end