所以我有一定的冰淇淋,我想得到的销售额在安大略的低脂冰淇淋和非过期,说。
IceCream有_多个安大略_sales_receipts:
included_ice_cream = IceCream.produced_this_or_previous_month.where(low_fat: true, expired: false)
final_amount = included_ice_cream.ontario_sales_receipts.pluck(:number_of_buckets).sum * BUCKET_PRICE
字符串
但这会导致:
undefined method `ontario_sales_receipts' for #<IceCream::ActiveRecord_Relation:0x0055de80e3ffa8>
型
如何从ActiveRecord关系中提供has_many关联?
我最初可以查询OntarioSaleRecept,但我不知道如何根据它们与特定IceCream的has_one关联来查询它们
included_ontario_sales_receipts = OntarioSalesReceipt.where( their associated IceCream is lowfat and non expired ... )
型
1条答案
按热度按时间hgb9j2n61#
字符串
这个怎么样?