ruby on rails - Getting Records Based on Count of Associated Model -



ruby on rails - Getting Records Based on Count of Associated Model -

i want utilize statement following:

baseproduct.where(baseproduct.products.count => 1)

this doesn't work.i undefined method 'products' class xyz.

in rails console though, can do

baseproduct.first.products

and output.

how records associated model count 1?

associations:

class baseproduct < activerecord::base has_many :products end class product < activerecord::base belongs_to :base_product end

please seek this

product.select('base_product_id, count(base_product_id) c').includes('base_product').group('products.base_product_id').having('c > 1')

ruby-on-rails ruby

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -