【发布时间】:2016-03-22 14:52:27
【问题描述】:
Document has_many :items
Item belongs_to :document
我需要查找其items.quantity * items.value_net的乘积之和大于某个值的文档。
我试过范围:
scope :items_value_net_gteq, lambda { |value|
joins(:items)
.where('SUM(items.quantity * items.price_net) >= ?', value)
}
但这是错误的。我一定遗漏了一些明显的东西。
【问题讨论】:
标签: mysql ruby-on-rails scope