我在rails中编写原始查询并使用以下命令执行:
ActiveRecord::Base.connection.execute(query)
有没有更好的方法来转换它?:
completions.type IN ('#{params[:certification].join("','")}')
,其中
params[:certification]
#=> ['Gold', 'Platinum']
我希望它像
completions.type IN ('Gold', 'Platinum')
同样的方式有效记录
Completion.where(type: ['Gold', 'Platinum'])
这是我的查询,我无法用活动记录
写SELECT type, json_array_elements(
replace(
(completions::json)::character varying,
'null',
'[]'
)::json) AS completions_json
FROM completions
WHERE completions.type IN ('#{params[:certification].join("','")}')
AND (
date(completions_json->>'completed_at')
BETWEEN date('2015-10-01')
AND date('2015-12-01')
)