Haseeb Ahmad
Haseeb Ahmad

Reputation: 8730

Nested query for association

Campaign has_many:ads

Ad

belongs_to: campaign
has_many :likes

Like

belongs_to :ad

I want to count the likes of all ads in campaign.How I query it?

Upvotes: 1

Views: 56

Answers (1)

user1414900
user1414900

Reputation: 91

Add relation to Campaign

has_many :likes, through: :ads

after that you can use: campaign.likes.count

Upvotes: 2

Related Questions