[英]how to query an array column in rails? with where condition?
i am having the following columns in my table t.string :appr_status , type: Array, default: []
and t.integer :employee_id
and my current query is 我在表
t.string :appr_status , type: Array, default: []
具有以下列t.string :appr_status , type: Array, default: []
和t.integer :employee_id
,当前查询是
@reg_req = AttendanceChangeRequest.where("employee_id IN (?)", emp_id_arr).to_a
where emp_id_arr
is an array like [1,2,3]
. 其中
emp_id_arr
是类似于[1,2,3]
的数组。 and i want to change the above query to this. 我想将以上查询更改为此。
AttendanceChangeRequest.where('(employee_id IN = ? AND appr_status contain= ?) ', emp_id_arr , appr_array )
where appr_array = ["1_app","2_app", "3_appr","4_appr"] is this. 其中appr_array = [“ 1_app”,“ 2_app”,“ 3_appr”,“ 4_appr”]是这里。 i want to get all the records when any one of the employee id is present in the passing array that is
emp_id_arr
and appr_status column should contain all values which are present in the passing array to the query (that is in appr_array
) if one value is also not present then i dont want that record. 当一个雇员ID出现在
emp_id_arr
的传递数组中时,我想获取所有记录,并且appr_status列应包含查询的传递数组(即appr_array
)中存在的所有值(如果一个值是)还不存在,那么我不想那个记录。 how to write this query? 如何编写此查询?
u need to like 你需要喜欢
AttendanceChangeRequest.where("'1_app' = ANY (appr_status)")
This will work correctly. 这将正常工作。
Try this: 尝试这个:
AttendanceChangeRequest.where(employee_id: emp_id_arr,appr_status: appr_array)
This is what you are looking? 这是你在找什么?
AttendanceChangeRequest.where("array_to_string(appr_status, '||') ILIKE :name", name: "%your desire search able value here%") AttendanceChangeRequest.where(“ array_to_string(appr_status,'||')ILIKE:name”,名称:“%your want search能力值%%”)
This is what you are looking? 这是你在找什么? what this query ll do.
这个查询会做什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.