【问题标题】:Order the result of a join订购连接的结果
【发布时间】:2014-03-08 02:45:14
【问题描述】:

我有两张桌子:

Deal has many Opportunities
Opportunity belongs to Deal

我正在尝试订购一个加入查询,该查询会根据机会的状态以及交易的状态显示机会列表。查询工作正常,除非我在末尾添加.order("deal.addr_street desc")。

@opportunities = Opportunity.joins(:opportunity_status).where("opportunity_statuses.id in (1, 2, 3, 6)").joins(:deal).merge(Deal.joins(:deal_status).where("deal_statuses.deal_status in ('On Market', 'Pre-sale')")).order("deal.addr_street desc")

错误是:

*SQLException: 没有这样的列:opportunities.deal.addr_street: SELECT "opportunities".* FROM "opportunities" INNER JOIN "opportunity_statuses" ON "opportunity_statuses"."id" = “机会”。“opportunity_status_id” INNER JOIN “交易” ON "deals"."id" = "opportunities"."deal_id" 左外连接 "deal_statuses" ON "deal_statuses"."id" = "deals"."deal_status_id" WHERE((1、2、3、6)中的opportunity_statuses.id)和 (deal_statuses.deal_status in ('On Market', 'Pre-sale')) ORDER BY 机会.deal.addr_street desc*

有人能告诉我如何订购加入的结果吗?我在rails4上

尼克

【问题讨论】:

  • 我认为这只是在order 调用中将deal 表名复数为:order("deals.addr_street desc") 的问题。
  • 感谢修复。如果您做出正确的回复,我会将其设置为答案。

标签: ruby-on-rails


【解决方案1】:

你需要在 order 子句中复数你的表名

(...).order("deals.addr_street desc")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-30
    • 2016-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多