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 - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -