Mark Provan
Mark Provan

Reputation: 1061

ActiveRecord Relations

I have 3 Models:

Group

Feed

FeedItem

A Group has many Feeds and Feeds have many FeedItems

Is there anyway I can get all the Feeds in a Groups FeedItems from the Group?

I guess something like group.feeds.feed_items ?

Upvotes: 0

Views: 210

Answers (1)

Baldrick
Baldrick

Reputation: 24350

I think what you're looking for is the through association. Add the following line to your Group model

has_many :feed_items, :through => :feeds

After that, you can access all the FeedItems in a group via group.feed_items

Upvotes: 2

Related Questions