我正在使用 Money-Rails 作为字段,如下所示:
class Product
...
field :price_GBP, type: Money
...
end
我正在尝试获取所有price_GBP
文档的平均值。如果该price_GBP
字段是浮点数或整数,我会这样:
avg = Product.avg(:price_GBP)
这将为我提供所有产品的平均价格。我试过了:
avg = Product.avg(":price_GBP.cents") #or
avg = Product.avg("price_GBP.fractional")
但两者都不起作用。有任何想法吗?
编辑:
这是price_GBP
属性:
price_GBP: {
cents: 220,
currency_iso: "GBP"
},