given a setup like class Parent has_many :child_parents has_many :children, :through => child_parents end and assuming i''d like to store the style of relationship on the child_parents table, for example create table child_parents( parent_id child_id is_adopted ) in otherwords, ''is_adopted'' is an attribute of the link between child and parent, not of the child or parent themselves, how can one access this simply? child = parent.children.first p child.adopted? is obviously desirable and used to be possible with HABTM associations. but that''s deprecated.... however there seems to be no easy way to accomplish something similar with full blown join models. cheers. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 28 Paź, 20:53, "ara.t.howard" <ara.t.how...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> given a setup like > > class Parent > has_many :child_parents > has_many :children, :through => child_parents > end > > and assuming i''d like to store the style of relationship on the > child_parents table, for example > > create table child_parents( > parent_id > child_id > is_adopted > ) > > in otherwords, ''is_adopted'' is an attribute of the link between child > and parent, not of the child or parent themselves, how can one access > this simply? > > child = parent.children.first > p child.adopted? > > is obviously desirable and used to be possible with HABTM > associations. but that''s deprecated.... however there seems to be no > easy way to accomplish something similar with full blown join models. > > cheers.http://wiki.rubyonrails.org/rails/pages/has_and_belongs_to_many "... has_and_belongs_to_many is great for what it does, but it is only adequate for simple many-to-many relationships. If your intermediary table needs to track additional data, then you may instead want to use ThroughAssociations instead. ..." Cheers --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org 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 -~----------~----~----~----~------~----~------~--~---
yeah i''m aware of all that - the issue is that using HM:T give no simple method of getting back at the *particular* model/row used for the join. of course there can by more that one, but it''s also the case that for any given pair of related objects there is exactly one row in the join model making that relationship and AR provides no handle on this record, which makes decorating it rather tricky. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
ara.t.howard wrote:> given a setup like > > class Parent > has_many :child_parents > has_many :children, :through => child_parents > end > > and assuming i''d like to store the style of relationship on the > child_parents table, for example > > create table child_parents( > parent_id > child_id > is_adopted > ) > > in otherwords, ''is_adopted'' is an attribute of the link between child > and parent, not of the child or parent themselves, how can one access > this simply? > > child = parent.children.first > p child.adopted?cp = parent.child_parents.first child = cp.child p cp.adopted? -- Rails Wheels - Find Plugins, List & Sell Plugins - http://railswheels.com --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---