是否可以向模型添加虚拟列(不是虚拟属性!)?
我有以下情况:AProduct(id, name)
有很多ProductVariant(id, price, offer_price, product_id,...)
当我选择所有产品时,我希望从ProductVariants
产品结果中的所有产品中获得最低产品价格。
@products = Product.with_min_price.order('min_price ASC')
我在 sql 查询 () 中计算最低价格,with_min_price
并希望将此min_price
值添加到Product
我的@products result
.