Rails:两个"where"查询-每个查询都单独工作,但不能一起工作 [英] Rails: Two 'where' queries - each works individually, but not together
本文介绍了Rails:两个"where"查询-每个查询都单独工作,但不能一起工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想写一些类似的东西:
I want to write something like:
@meeting_requests = Meeting.where('meeting_time >= ? AND requestee_id IS ?
AND status = ?', Date.today, nil, "Active")
.joins(:requestor)
.where('birthyear >= ? AND birthyear <= ?',
current_user.birthyear - 10,
current_user.birthyear + 10 )
这有效:
@meeting_requests = Meeting.where('meeting_time >= ? AND requestee_id IS ?
AND status = ?', Date.today, nil, "Active")
这可行:
@meeting_requests = Meeting.joins(:requestor)
.where('birthyear >= ? AND birthyear <= ?',
current_user.birthyear - 10,
current_user.birthyear + 10 )
类似这样的作品:
Meeting.joins(:requestor).where('birthyear > ?', 1900).where(status: "Active")
但是我需要在Meeting_time上做比查询更多的事情,所以我需要将它写为我认为是字符串?
but I need to do a greater than query on the meeting_time, so I need to write it as a string I think?
但是两个SQL查询一起产生错误:ambiguous column name: status: SELECT
But together both sql queries produce an error of: ambiguous column name: status: SELECT
我觉得我已经很近了……我在这里想念什么?
I feel like I'm so close... what am I missing here?
推荐答案
当不清楚列来自哪个表时,将显示此消息.这应该起作用:
This is a message that appears when it is not clear which table the column comes from. This should work:
...rest_of_statement.where('meetings.status' => 'Active')
这篇关于Rails:两个"where"查询-每个查询都单独工作,但不能一起工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文