有兩種模式:折扣和時間折扣。範圍與模型協會在軌道4
折扣has_one
TimeDiscount和TimeDiscount belongs_to
折扣。
我需要得到所有TimeDiscounts
與關聯Discount.is_enabled
等於true
。我該怎麼做?我知道關於範圍,我可以做類似於這件事:
scope :new_orders, -> { where(order_status: OrderStatus.new_order) }
請告訴我如何利用這裏的關聯。
http://stackoverflow.com/questions/5874118/scope-with-joins-to-get-data-in-rails-3 – emaillenin
你得到你的答案? –