How to define three way many to many relations using belongsToMany?

39 views
Skip to first unread message

Bruce Chou

unread,
Apr 30, 2015, 10:17:18 AM4/30/15
to sequ...@googlegroups.com
Hi all,

  I'm trying to create a database which contains a three way many to many to many relation. For example: A teacher gave a talk for a specific field at a meeting room

(Teacher, field and room are 3 standalone tables with primary key.)


I tried to create this relation by the following snippets:

1) Field.belongsToMany(models.Teacher , {through: 'TeachersGiveTalksAtRooms'});

    Field.belongsToMany(models.Room, {through: 'TeachersGiveTalksAtRooms'});

2) Room.belongsToMany(models.Field, {through: 'TeachersGiveTalksAtRooms'});

    Room.belongsToMany(models.Teacher, {through: 'TeachersGiveTalksAtRooms'});

3) Teacher.belongsToMany(models.Room, {through: 'TeachersGiveTalksAtRooms'});

    Teacher.belongsToMany(models.Field, {through: 'TeachersGiveTalksAtRooms'});


However, only two of the relations (Teacher & Field ) show up in the result table. Could anyone help? Thanks.


Mick Hansen

unread,
Apr 30, 2015, 11:53:31 AM4/30/15
to Bruce Chou, sequ...@googlegroups.com
We don't currently support >= 3 N:M relations.
You'll have to manually maintain and include the join table.
--
Mick Hansen
@mhansendev
mhansen.io

Bruce C. Chou (周敬程)

unread,
Apr 30, 2015, 7:04:17 PM4/30/15
to Mick Hansen, sequ...@googlegroups.com
ok I will do it manually. Thank you~
Reply all
Reply to author
Forward
0 new messages