![](/img/trans.png)
[英]ActiveRecord joins throwing Column in where clause is ambiguous error - Rails 5.1
[英]Activerecord syntax of where clause on joins
我想选择所有在两个日期之间创建了订单的订单项(订单具有列日期)
这是我想做的
LineItem.where(:product_id => self.id).joins(:order).where(:orders => {"date > ? and date < ?", date_start, date_end}).all
我无法弄清楚最后一个条件的语法...我知道在哪里工作:
.where("date > ? and date < ?", date_start, date_end)
还有这样的地方:
.where(:orders => {:id => 23043})
但是我该如何混合两种方式使我得到类似第一个请求的信息?
尝试这个
.where(:date => date_start..date_end, :order => {:id => 23043})
您只需将这些子句链接在一起,它将自动使用AND将它们连接在一起:
.where("date > ? and date < ?", date_start, date_end).
where(:orders => {:id => 23043})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.