【发布时间】:2014-02-28 06:21:05
【问题描述】:
有两种模式:Discount 和 TimeDiscount。
折扣has_oneTimeDiscount 和TimeDiscount belongs_to 折扣。
我需要获取所有 TimeDiscounts 以及相关联的 Discount.is_enabled 等于 true。我该怎么做?我知道范围界定,我可以做类似的事情:
scope :new_orders, -> { where(order_status: OrderStatus.new_order) }
请在这里告诉我如何使用关联。
【问题讨论】:
标签: ruby-on-rails activerecord model-associations