3
私はバリアントの価格がで、比較価格が未満のすべてのバリアントをフィルタリングするためにActiveRecordクエリを作成しようとしています。ここに私のバリエーションモデルがあります:関連するテーブルの計算でどのようにフィルタリングするのですか?
class Variant < ApplicationRecord
has_and_belongs_to_many :comparisons,
class_name: "Variant",
foreign_key: "competitor_variant_id",
association_foreign_key: "account_variant_id",
join_table: "comparisons"
belongs_to :parent, polymorphic: true
end
は、ここで私はこれまで持っているものです:
joins(:comparisons).where('variants.price < comparisons_variants.min(:price)').distinct