我不确定我是否知道在事件记录中编写此 SQL 查询而不完全手动编写的最佳方法。本质上我想编写这两个查询的组合。
这个查询本质上是我试图重新创建的联接。我想确保返回的任何条目只是那些 image_path_processing 标志设置为 false 的图像。
@entries = ContestEntry.joins(:entry_images).where(contest_id: @contest.id, entry_images: {
image_path_processing: false
}).limit(10)
但是我正在编写的查询遇到的问题是我需要包含来自网址的参数,并且我不确定上述语法是否正确删除了 sql_injection
这是我尝试添加条件连接的内容。
@entries = ContestEntry.where("contest_id = ? and created_at > ?",
params[:contest_id], Time.at(params[:after].to_i + 1))
最佳答案
你能试试这个吗?
@entries = ContestEntry.joins(:entry_images).
where(contest_id: params[:contest_id],
entry_images: { image_path_processing: false }).
where('contest_entries.created_at > ?', Time.at(params[:after].to_i+1)).
limit(10)
关于ruby-on-rails - Active Record 与条件参数连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15254655/