I wonder, why I always have to also specify the has_many :assignments association in both of the models in question when using :through? Is this DRY? Are there cases when I do not need to specify them, or when they differ? Thank you for explanation.
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
Update
It seems I wasn't clear enough that I'm talking about has_many :through! So the answers given to this point don't really fit my question. So again:
Why do I always need a has_many :assignments
when I already have a has_many :projects, :through => :assignments
? Shouldn't Rails just add has_many :assignments
itself automatically?