Forum: Ruby on Rails Re: Accessing model info

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
52cb4115a870ff1942e7e1ae96f4306f?d=identicon&s=25 Tyler MacDonald (Guest)
on 2007-03-14 21:55
(Received via mailing list)
Mick <rails-mailing-list@andreas-s.net> 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
This topic is locked and can not be replied to.