ruby on rails - Nested query for association -


campaign has_many:ads

ad

belongs_to: campaign has_many :likes 

like

belongs_to :ad 

i want count likes of ads in campaign.how query it?

add relation campaign

has_many :likes, through: :ads 

after can use: campaign.likes.count


Comments

Popular posts from this blog

php - Extract Text from HTTP referer -

Receive udp packets in android gstreamer -

ios - How to Rectify the Relationship Fault in CoreData While parsing RESTKIT? -