我的“产品”表 has_many :registered_products。
我想用类似的东西
products.find(:has_registered_products)
其中仅返回在 Registered_products 表中也有条目的产品。我怎样才能做到这一点?
只要您在注册产品表中有产品的外键,您就可以执行以下操作:
has_many :registered_products
named_scope :with_registered_products, :joins => :registered_products
# if you're using rails 3
scope :with_registered_products, joins(:registered_products)
并且只会返回至少具有一种关联注册产品的产品。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)