많은 ActiveRecord 모델과 관련된 대화를 할 수있는 프로젝트를 진행 중입니다. 사용자는 사이트의 모든면을 토의 할 수 있습니다. 이것이 어떻게 구현되어야하는지에 대한 두 가지 아이디어가 있습니다.RoR :이 시나리오에서 belongs_to, : polymorphic을 사용해야합니까?
1), 자산에없는 대화를 belongs_to를 사용 - 대화가 자산
class Product< ActiveRecord::Base
belongs_to :conversation
end
class PurchaseOrder < ActiveRecord::Base
belongs_to :conversation
end
2) 전혀 모르고있을 것입니다 belongs_to를 사용 : 다형성 => 사실을 대화에
class Conversation < ActiveRecord::Base
belongs_to :asset, :polymorphic => true
end
class Product < ActiveRecord::Base
has_one :conversation, :as => :asset
end
class PurchaseOrder < ActiveRecord::Base
has_one :conversation, :as => :asset
end
이 관계를 모델링하는 올바른 방법은 무엇입니까? 관계를 진술하면 "제품/구매 주문서에는 하나의 대화가있을 수 있습니다"라고 말하고 싶습니다.
좋은 답변입니다. 귀하의 통찰력에 감사드립니다. –