MySQL多对多的实现是使用中间表来进行关联。
user 是 owner ,那么表名就是 user_roles,如果 role 是 owner ,那么表名就是 role_users,如果没有显式的声明 owner,则在查询时确定;
比方:使用 userRepository 查询:
userRepository.find({}, {
populate: ['roles'],
})
此时的的表名是 role_roles,如果使用 roleRepository 查询:
roleRepository.find({}, {
populate: ['users'],
})
此时的查询的表是 role_users,所以我们要显示的声明好那一侧是 owner,这很重要,不然查询的表名就会变去。
正文完