Hello there, a Person has_many projects, and a Project has_many tasks. Thus, a Person also has many tasks. Is there a way to write this has_many in the Person class without using :finder_sql? Thanks a bunch in advance! Giuseppe -- 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 -~----------~----~----~----~------~----~------~--~---
On Tue, Jun 17, 2008 at 2:54 AM, Giuseppe Bertini < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hello there, > > a Person has_many projects, and a Project has_many tasks. > Thus, a Person also has many tasks. > > Is there a way to write this has_many in the Person class without using > :finder_sql? > >class Task < ActiveRecord::Base belongs_to :project end class Project < ActiveRecord::Base belongs_to :person has_many :tasks end class Person < ActiveRecord::Base has_many :projects has_many :tasks, :through => :projects end -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.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 -~----------~----~----~----~------~----~------~--~---
DUH! I had always thought that :through would only apply to a model that belongs_to the other two (like a join table). I should have tried this before going to the forum. Thanks Rick, Giuseppe Rick Denatale wrote:> class Task < ActiveRecord::Base > belongs_to :project > end > > class Project < ActiveRecord::Base > belongs_to :person > has_many :tasks > end > > class Person < ActiveRecord::Base > has_many :projects > has_many :tasks, :through => :projects > end-- 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 -~----------~----~----~----~------~----~------~--~---