rails - are my associations correct?
I am beginning my first rails application and I would just like to make
sure that my associations will work like I am hoping. Here is an overview
of the models in my application:
class School < ActiveRecord::Base
has_many :courses
has_many :teachers, :through => :courses
has_many :students, :through => :courses
end
class Course < ActiveRecord::Base
belongs_to :school
belongs_to :teacher
has_and_belongs_to_many :students
end
class Teacher < ActiveRecord::Base
has_many :courses
has_many :students, :through => :courses
end
class Student < ActiveRecord::Base
has_and_belongs_to_many :courses
has_many :teachers, :through => :courses
end
The one thing I have noticed so far is that if I try to get the teachers
or students in a school it will return the same record multiple times. I
am aware I can just call uniq but I would prefer not having to doing that.
So I am wondering if there is a better way I can do this.
No comments:
Post a Comment