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 -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -