Is there anyway to get the join table attributes to show up as attributes on the has_many association when the has_many is eager loaded. I think the eager loaded part is the gotcha to all this. For example, if I have book.contributors, and the join table "contributions" had a contribution_date on it. How can I get the date onto the contributors'' objects. That way I can do book.contributors[0].contribution_date. Is it not possible to do when its included? -- Posted via http://www.ruby-forum.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 -~----------~----~----~----~------~----~------~--~---
Mark Reginald James
2007-May-20 11:19 UTC
Re: join table attributes piggy backed with has_many through
Aryk Grosz wrote:> Is there anyway to get the join table attributes to show up as > attributes on the has_many association when the has_many is eager > loaded. I think the eager loaded part is the gotcha to all this. > > For example, if I have book.contributors, and the join table > "contributions" had a contribution_date on it. How can I get the date > onto the contributors'' objects. > > That way I can do book.contributors[0].contribution_date. Is it not > possible to do when its included?The attributes should be there if you''re using has_and_belongs_to_many. But if you''re using has_many_through, eager load like this book = Book.find(..., :include => {:contributions => :contributor}) Then access like this: book.contributions[0].contribution_date book.contributions[0].contributor.name -- We develop, watch us RoR, in numbers too big to ignore. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---