Hey everyone, I have a quick question on a tricky model for the app I''m working on. I have a Tasks model, and a Task can be assigned to a User; a Task should also know the User who assigned (created) it, and be updatable by that user. The idea is so the View can have something like on a "My Tasks" page: Assigned by John Smith on June 1st, 2008 Since it has to have two references to the same model (User), one for who has been assigned to, and one for who did the assigning, what association should I be looking at? The associations in Rails are a little confusing beyond the basic belongs_to/has_one/has_many things, so I''m not sure what I should use. has_and_belongs_to_many? has_many :through? Any help would be appreciated. - Wayne --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
fields in tasks: user_id and assigning_user_id in the task model: belongs_to :user belongs_to :assigning_user, :class => "User" in the user model: has_many :tasks has_many :assigned_tasks, :as => "assigning_user" On Thu, May 29, 2008 at 11:42 AM, Wayne Molina <wayne.molina-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hey everyone, > > I have a quick question on a tricky model for the app I''m working on. > I have a Tasks model, and a Task can be assigned to a User; a Task > should also know the User who assigned (created) it, and be updatable > by that user. The idea is so the View can have something like on a > "My Tasks" page: > > Assigned by John Smith on June 1st, 2008 > > Since it has to have two references to the same model (User), one for > who has been assigned to, and one for who did the assigning, what > association should I be looking at? The associations in Rails are a > little confusing beyond the basic belongs_to/has_one/has_many things, > so I''m not sure what I should use. has_and_belongs_to_many? > has_many :through? > > Any help would be appreciated. > > - Wayne > > > >-- Appreciated my help? Recommend me on Working With Rails http://workingwithrails.com/person/11030-ryan-bigg --~--~---------~--~----~------------~-------~--~----~ 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 29 May 2008, at 03:15, Ryan Bigg (Radar) wrote:> fields in tasks: user_id and assigning_user_id > > in the task model: > > belongs_to :user > belongs_to :assigning_user, :class => "User" > > in the user model: > > has_many :tasks > has_many :assigned_tasks, :as => "assigning_user" >that should be :foreign_key => "assigning_user_id". I wrote up a reasonably detailed walkthrough of this sort of thing at http://spacevatican.org/2008/5/6/creating-multiple-associations-with-the-same-table Fred> > On Thu, May 29, 2008 at 11:42 AM, Wayne Molina > <wayne.molina-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hey everyone, > > I have a quick question on a tricky model for the app I''m working on. > I have a Tasks model, and a Task can be assigned to a User; a Task > should also know the User who assigned (created) it, and be updatable > by that user. The idea is so the View can have something like on a > "My Tasks" page: > > Assigned by John Smith on June 1st, 2008 > > Since it has to have two references to the same model (User), one for > who has been assigned to, and one for who did the assigning, what > association should I be looking at? The associations in Rails are a > little confusing beyond the basic belongs_to/has_one/has_many things, > so I''m not sure what I should use. has_and_belongs_to_many? > has_many :through? > > Any help would be appreciated. > > - Wayne > > > > > > -- > Appreciated my help? > Recommend me on Working With Rails > http://workingwithrails.com/person/11030-ryan-bigg > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I''ll check that link out - thanks all! - Wayne On May 29, 2008, at 4:43 AM, Frederick Cheung wrote:> > > On 29 May 2008, at 03:15, Ryan Bigg (Radar) wrote: > >> fields in tasks: user_id and assigning_user_id >> >> in the task model: >> >> belongs_to :user >> belongs_to :assigning_user, :class => "User" >> >> in the user model: >> >> has_many :tasks >> has_many :assigned_tasks, :as => "assigning_user" >> > that should be :foreign_key => "assigning_user_id". > I wrote up a reasonably detailed walkthrough of this sort of thing > at http://spacevatican.org/2008/5/6/creating-multiple-associations-with-the-same-table > > Fred > > >> >> On Thu, May 29, 2008 at 11:42 AM, Wayne Molina >> <wayne.molina-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> Hey everyone, >> >> I have a quick question on a tricky model for the app I''m working on. >> I have a Tasks model, and a Task can be assigned to a User; a Task >> should also know the User who assigned (created) it, and be updatable >> by that user. The idea is so the View can have something like on a >> "My Tasks" page: >> >> Assigned by John Smith on June 1st, 2008 >> >> Since it has to have two references to the same model (User), one for >> who has been assigned to, and one for who did the assigning, what >> association should I be looking at? The associations in Rails are a >> little confusing beyond the basic belongs_to/has_one/has_many things, >> so I''m not sure what I should use. has_and_belongs_to_many? >> has_many :through? >> >> Any help would be appreciated. >> >> - Wayne >> >> >> >> >> >> -- >> Appreciated my help? >> Recommend me on Working With Rails >> http://workingwithrails.com/person/11030-ryan-bigg >>> > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---