[英]Dynamic query in rails where condition
How can we get a dynamic query in Rails such that we can only search the field that is present in the array with AND operator? 我们如何在Rails中获得动态查询,使得我们只能使用AND运算符搜索数组中存在的字段? Example:
例:
car_type = ['tow', 'drive']
Vehicle.where("tow=? AND drive=?", true, true)
car_type = ['tow']
Vehicle.where("tow=?", true)
You could do something like: 您可以执行以下操作:
q = { tow: true, drive: true }
Vehicle.where(q)
You can get q
dinamically doing: 你可以
q
做:
q = car_type.product([true]).to_h
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.