has_one
and belongs_to
in your models.Note: one-to-one relationship does not support through associations yet.
coach
and coach=
instance methods to the team which returns associated coach.team
and team=
instance method to the coach.team_id
and index to your coaches table:has_one
. In above case team_id
is assumed to be present in coaches
table. In case its different you can specify one like this:belongs_to
and has_many
macros provide a rails like mapping between Objects.posts
instance method to the user which returns an array of posts.user
and user=
instance method to the post.user_id
and index to your posts table:users
that belong to many rooms
. We recommend adding a new model called participants
to represent the many-to-many relationship.belongs_to
and has_many
relationships going both ways.through:
clause to simplify accessing the many-to-many relationship: