On 19 March 2010 03:49, dan <[email protected]> wrote:
> now imagine that attribute_objects also contains a rating
> so when i say, object.attributes, id like to get the rating too
> that doesnt seem to be possible with the has_many relationship
> if i could force the join on the object attributes to bring the
> attribute_objects fields also...maybe

If you want to access properties of AttributeObjects [1], you can
iterate the collection of them, not the collection of attributes.
So instead of:

@object.attributes.each do |attribute|
  attribute.name ....
end

you do this:
@object.attribute_objects.each do |attribute_object|
  attribute_object.attribute.name ....
  attribute_object.rating ....
end

> i think i have to write custom sql for this

You can if you want... but you don't *have* to.
You can possibly use the ":finder_sql" option of the association to
specify your own conditions for populating the collection (I've been
fiddling with it here for 10mins, and not got it working... post up
some working code if it does it for you :-)
http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html


[1] All your class names are plural; they should really be singular...

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to