Re: Accessing model info


#1

Mick removed_email_address@domain.invalid 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