On 19 April 2013 16:09, Leandro Peracchi <[email protected]> wrote:
> Hi Colin!
>
>   Thanks for your tips.  :)
> ...
> = Models =
>
> class School < ActiveRecord::Base
>   has_many :teams
> end
>
> class Team < ActiveRecord::Base
>   belongs_to :school
>
>   has_many :teachers
>   has_many :people, :through => :teachers
>
>   has_many :students
>   has_many :people, :through => :students
> end
>
> class Person < ActiveRecord::Base
> end
>
> class Teacher < ActiveRecord::Base
>   belongs_to :team
>   belongs_to :person
> end
>
> class Student < ActiveRecord::Base
>   belongs_to :team
>   belongs_to :person
> end

I would not do it like that.  I would just have a people table that
contains all the students and teachers, without the separate classes.
Look up self referential associations to see how you can then have
@person.students (which will be people) and @person.teacher.  If you
want the classes then you could use STI.

Colin

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to