【发布时间】:2021-06-17 11:57:31
【问题描述】:
product.rb
class Product < ApplicationRecord
has_many :product_items
end
product_item.rb
class ProductItem < ApplicationRecord
belongs_to :product
has_many :prices
end
price.rb
class Price < ApplicationRecord
belongs_to :product_item
end
现在价格表有一个名为otc的列,它存储产品项目的一次性成本,产品项目可以有多个价格。
目标:产品有很多产品,但我需要找到一个最低成本的产品项目(比如default_product_item)。需要从价格表中为最低 otc 的产品选择产品项目(以及 otc)。
我正在使用 ruby 3.0.1、rails 6.1.3.2、数据库、Postgres。
【问题讨论】:
-
您要退货还是退货?
-
希望以最低价格获得产品。