私はContributor
モデルとモデルを持っていResource
ます。単純な世界では、次の設定があります。
class Resource
has_many :authorships
has_many :contributors, through: :authorships
end
class Contributor
has_many :authorships
has_many :resources, through: :authorships
end
ただし、私の要件は変更されました。寄稿者は、リソースの編集者またはリソースの作成者になることができるようになりました。Contributor
はEditor
、あるリソースの であり、別のリソースの である場合がAuthor
あります。したがって、この要件を処理するには2つの方法があるようです。
何らかの
is_editor?
属性をAuthorships
結合モデルに追加し、各関係に効果的に注釈を付けます。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
最も賢明なアプローチはどれですか、または私が見逃している別のアプローチはありますか?