【发布时间】:2010-02-14 15:30:20
【问题描述】:
我有一个 Order 和 Orderdetails
Orderdetails belongs_to Order
Order has_many Orderdetails
我正在尝试将以下查询转换为 ActiveRecord count 函数
select Count(*)
from orderdetails A, orders B
where A.prodid='6' and A.orderid= B.id and B.custid='11'
我试过了:
@count = Orderdetail.count(:conditions => "prodid = 6 and order.custid = 11")
但是,这会产生错误:
PGError: ERROR: syntax error at or near "order"
LINE 1: ...unt_all FROM "orderdetails" WHERE (prodid = 6 and order.cust...
编辑 我改为订购s
但现在我收到此错误:
ActiveRecord::StatementInvalid: PGError:错误:缺少 FROM 子句 表“订单”第 1 行的条目: ...unt_all FROM "orderdetails" WHERE (prodid = 6 和 orders.cus...
【问题讨论】:
-
表名不应该是“orders”吗?
-
涂料。修复了一些东西。现在我得到不同的错误。如何在 from 中添加订单?
标签: ruby-on-rails activerecord