hi there, lets say you have: A that belongs_to :b, and B belongs_to :c how do you normally go about saying A belongs_to :c, :through => :b ?? searching I found two solutions: 1. method: class A def c b.c end end and 2.delegate: class A delegate :c, :to => :b end but neither will have the benefits of generated sql with joins. How you normally do this? and What are the reasons against having it on rails itself? greetings joaquin -- www.least-significant-bit.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Joaquin Rivera padron wrote:> hi there, > lets say you have: A that belongs_to :b, and B belongs_to :c > > how do you normally go about saying A belongs_to :c, :through => :b ??If A belongs_to :b, that means that Rails expects a b_id field in A''s table. In your case, that doesn''t exist, so what you want is A has_one :c, :through => :b Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser wrote:> Joaquin Rivera padron wrote: >> hi there, >> lets say you have: A that belongs_to :b, and B belongs_to :c >> >> how do you normally go about saying A belongs_to :c, :through => :b ?? > > If A belongs_to :b, that means that Rails expects a b_id field in A''s > table. In your case, that doesn''t exist, so what you want is > A has_one :c, :through => :bWow, that was stupid of me. I must not have been awake when I wrote that. has_one :through will probably work, but my explanation is totally inaccurate. Sorry.> > Best, > -- > Marnen Laibow-Koser > http://www.marnen.org > marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.