如何在 ActiveRecord 查询中添加 "and !="
How to add "and !=" in ActiveRecord query
我需要在此查询中使用 AND
和 !=
再添加一个条件
(即:和 properties.property_type_id != 'NULL')
如何添加到这个活动记录中?
@properties = Property.where(category_id: Admin
.select("category_id").where(id: current_user.id))
请帮忙
任何帮助都是值得赞赏的
试试这个
@properties = Property.where("category_id IN (?) AND property_type_id IS NOT NULL", Admin.where(id: current_user.id).map(&:category_id) )
希望对您有所帮助
您好'and'查询正在向查询添加一个where条件。
@properties = Property.where(category_id: Admin.select("category_id").where(id: current_user.id)).where('property_type_id is NOT NULL')
您最初需要映射所有 category_ids
category_ids = Admin.where(:id => current_user.id).map(&:category_id)
这将 return 您需要的所有 category_ids。
现在您从 属性 table 中获取所需的结果。
@properties = Property.where("category_id IN (?) AND property_type_id IS NOT NULL",category_ids)
我需要在此查询中使用 AND
和 !=
再添加一个条件
(即:和 properties.property_type_id != 'NULL')
如何添加到这个活动记录中?
@properties = Property.where(category_id: Admin
.select("category_id").where(id: current_user.id))
请帮忙 任何帮助都是值得赞赏的
试试这个
@properties = Property.where("category_id IN (?) AND property_type_id IS NOT NULL", Admin.where(id: current_user.id).map(&:category_id) )
希望对您有所帮助
您好'and'查询正在向查询添加一个where条件。
@properties = Property.where(category_id: Admin.select("category_id").where(id: current_user.id)).where('property_type_id is NOT NULL')
您最初需要映射所有 category_ids
category_ids = Admin.where(:id => current_user.id).map(&:category_id)
这将 return 您需要的所有 category_ids。
现在您从 属性 table 中获取所需的结果。
@properties = Property.where("category_id IN (?) AND property_type_id IS NOT NULL",category_ids)