契約、サービス、価格の 3 つのモデルがあります。
class Agreement < ActiveRecord::Base
has_many :prices, as: :priceable
end
class Service < ActiveRecord::Base
has_many :prices, as: :priceable
end
class Price < ActiveRecord::Base
attr_accessible :price, :price_currency, :priceable_id, :priceable_type
belongs_to :priceable, polymorphic: true
end
しかし、サービス customer_price と Agency_price には 2 つの価格タイプがあります。契約に価格タイプがありません。以下のようなものをモデル化したいと思います。それはどのように可能ですか?
class Agreement < ActiveRecord::Base
has_many :prices, as: :priceable
end
class Service < ActiveRecord::Base
has_many :customer_prices, as: :priceable # I think I should write something here
has_many :agency_prices, as: :priceable # I think I should write something here
end
class Price < ActiveRecord::Base
attr_accessible :price, :price_currency, :priceable_id, :priceable_type
belongs_to :priceable, polymorphic: true
end
ベストアプローチとは?AgreementPrice と ServicePrice のような 2 つの価格モデルを作成する必要があるかもしれません。よろしくお願いします。