ruby on rails - Virtual columns in a model -
is possible add virtual column model (not virtual attribute!)?
i have following situation: product(id, name)
has many productvariant(id, price, offer_price, product_id,...)
when select products want have minimum product price productvariants
in products result.
@products = product.with_min_price.order('min_price asc')
i calculate minimum price in sql query (with_min_price
) , want add min_price
value each product
in @products result
.
this method in product class assuming product has_many productvarients
#product model def min_product_price product_variants.map(&:price).min end
Comments
Post a Comment