MESSYKILL5000
2008-Feb-13 02:40 UTC
has many through: Users, Reservations, and the zen of being totally confused
Hey folks, This is a question about my rails app. It takes online reservations for a hotel. I''ve got a has many through relationship all set up and working: class User < ActiveRecord::Base has_many :reservations has_many :events, :through => :reservations end class Event < ActiveRecord::Base has_many :users, :through => :reservations end class Reservation < ActiveRecord::Base belongs_to :user belongs_to :event end My confusion comes when I try to actually manipulate this data. In the view, how do I show what users are linked to an event? How do I put a list of users in the event/show? Am I drunk enough to be this confused?! Can some brave soul shed light on this hairy-est of queries? Mahalos. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Rick DeNatale
2008-Feb-13 14:53 UTC
Re: has many through: Users, Reservations, and the zen of being totally confused
On 2/12/08, MESSYKILL5000 <john.d.perkins-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hey folks, > This is a question about my rails app. It takes online reservations > for a hotel. I''ve got a has many through relationship all set up and > working: > > class User < ActiveRecord::Base > has_many :reservations > has_many :events, :through => :reservations > end > > class Event < ActiveRecord::Base > has_many :users, :through => :reservations > end > > class Reservation < ActiveRecord::Base > belongs_to :user > belongs_to :event > end > > My confusion comes when I try to actually manipulate this data. In the > view, how do I show what users are linked to an event? How do I put a > list of users in the event/show? Am I drunk enough to be this > confused?! Can some brave soul shed light on this hairy-est of > queries?Well, if event is an Event, then event.users is the collection of its Users -- 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 -~----------~----~----~----~------~----~------~--~---