Thursday, March 18, 2010

[Rails] getting data from a through table

im using has_many through and the through table has some data i want
but i cant seem to access it using straight rails

<code>
class AttributeObjects < ActiveRecord::Base
belongs_to :attributes
belongs_to :objects
end

class Attributes < ActiveRecord::Base
has_many :attribute_objects
has_many :objects, :through => :attribute_objects
end

class Objects < ActiveRecord::Base
has_many :attribute_objects
has_many :attributes, :through => :attribute_objects
end

</code>

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

i think i have to write custom sql for this

--
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment