我有一个property
的{{1}}模型。
我想在我的belongs_to :property_type
模型上创建一个范围,以查找特定Property
的所有记录。
如何找到所有property_type
的{{1}}记录?
我尝试了以下方法:
property
也是这样:
property_type.name == "Residential"
答案 0 :(得分:2)
您可以使用联接对property_type进行过滤
Property.joins(:property_type).where(property_types: {name: "Residential"}).count
OR
Property.joins(:property_type).where("property_types.name = ?", "Residential").count