:through を使用するときに、問題の両方のモデルで常に has_many :assignments 関連付けも指定する必要があるのはなぜですか? これはDRYですか?指定しなくてもいい場合や、違う場合はありますか?説明ありがとうございます。
class Programmer < ActiveRecord::Base
has_many :projects, :through => :assignments
has_many :assignments # Why that?
end
class Project < ActiveRecord::Base
has_many :programmers, :through => :assignments
has_many :assignments # Why that?
end
class Assignment < ActiveRecord::Base
belongs_to :project
belongs_to :programmer
end
アップデート
has_many :throughについて話していることが十分に明確ではなかったようです。したがって、この時点で与えられた答えは、私の質問にはあまり当てはまりません。もう一度:
has_many :assignments
がすでにあるのに、なぜ常に が必要なのhas_many :projects, :through => :assignments
ですか? Rails はhas_many :assignments
自分自身を自動的に追加するべきではありませんか?