0

私はContributorモデルとモデルを持っていResourceます。単純な世界では、次の設定があります。

class Resource

   has_many :authorships
   has_many :contributors, through: :authorships

end

class Contributor

   has_many :authorships
   has_many :resources, through: :authorships

end

ただし、私の要件は変更されました。寄稿者は、リソースの編集者またはリソースの作成者になることができるようになりました。ContributorEditor、あるリソースの であり、別のリソースの である場合がAuthorあります。したがって、この要件を処理するには2つの方法があるようです。

  1. 何らかのis_editor?属性をAuthorships結合モデルに追加し、各関係に効果的に注釈を付けます。

  2. 2 番目の結合モデルを作成します – Editorship:

     class Resource
       has_many :authorships
       has_many :editorships
       has_many :contributors, through: :authorships
       has_many :contributors, through: :editorships
    
     end
    
     class Contributor
       has_many :authorships
       has_many :editorships
       has_many :resources, through: :authorships
       has_many :resources, through: :editorships
     end
    

最も賢明なアプローチはどれですか、または私が見逃している別のアプローチはありますか?

4

1 に答える 1

1

あなたの明確化を踏まえて、私は最初のアプローチを使用しますが、単にis_editorブール値を導入する代わりにAuthorship、言語と概念を一般化し、代わりにまたは のいずれかであるが、で拡張できるフィールドで使用ResourceContributorshipすることをお勧めします将来。contributor_type:author:editor

于 2013-09-26T19:19:18.053 に答える