【发布时间】:2015-10-12 07:30:10
【问题描述】:
我正在尝试搜索订单已完成的所有 LineItems。
# /spree/order.rb
def self.complete
where.not(completed_at: nil)
end
我试过了:
product.orders.complete.map { |o| o.line_items }.flatten
但它返回一个数组,我不能这样做.where(variant_id: ID)。
或:
product.orders.includes(:line_items).complete.where(line_items: { variant_id: 263})
但它说:PG::UndefinedTable: ERROR: missing FROM-clause entry for table "line_items"
然后我尝试了:
product.line_items.includes(:order).where(variant_id: ID).where.not(order: { completed_at: nil })
它返回ActiveRecord::ConfigurationError: Association named 'orders' was not found on Spree::LineItem; perhaps you misspelled it?
这种方式也可以:product.orders.complete ... 但不知道如何通过其 variant_id 搜索 LineItems。
我该如何解决?如何退回属于已完成订单的所有产品 LineItems?
非常感谢!
【问题讨论】:
标签: sql ruby-on-rails postgresql spree