Hi there, I have a model called Subscription which contains (and therefore links) a user_id and an event_id (both User and Event being additional models themselves). When I call Subscription.find(user_id = 1) for example, it will return a hash of all the records therein where user_id is equal to 1. How, then, do I access the full details of an event from the event ID''s returned? I hope this makes sense to someone, any help is appreciated! Cheers Mick -- 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 -~----------~----~----~----~------~----~------~--~---
Hi, data = Subscription.find(user_id = 1) p data.attributes # I think this will display every attribute connected to that object. puts "Subscribers lastname: #{data.lastname}" Not even 50% sure it´ll work, but give it a try! :) Regards, Martin Stabenfeldt On 14/03/07, Mick <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi there, > > I have a model called Subscription which contains (and therefore links) > a user_id and an event_id (both User and Event being additional models > themselves). > > When I call Subscription.find(user_id = 1) for example, it will return a > hash of all the records therein where user_id is equal to 1. > > How, then, do I access the full details of an event from the event ID''s > returned? > > I hope this makes sense to someone, any help is appreciated! > > Cheers > > Mick > > -- > 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mick <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I have a model called Subscription which contains (and therefore links) > a user_id and an event_id (both User and Event being additional models > themselves). > > When I call Subscription.find(user_id = 1) for example, it will return a > hash of all the records therein where user_id is equal to 1. > > How, then, do I access the full details of an event from the event ID''s > returned?Add "belongs_to :event" to your model object... then subscription_object.event Will be your "Event" object for that event. Cheers, Tyler --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---