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

maven fortify plugin : Unable to load build session with ID XXXXX .. See log file for more details -

c# - Primavera WebServices does not return any data -

android - Display emoji panel with genymotion - keyboard/touch input? -