MikroORM多对多模型定义

396次阅读
没有评论

MySQL多对多的实现是使用中间表来进行关联。

userowner ,那么表名就是 user_roles,如果 roleowner ,那么表名就是 role_users,如果没有显式的声明 owner,则在查询时确定;

比方:使用 userRepository 查询:

userRepository.find({}, {
  populate: ['roles'],
})

此时的的表名是 role_roles,如果使用 roleRepository 查询:

roleRepository.find({}, {
  populate: ['users'],
})
此时的查询的表是 role_users,所以我们要显示的声明好那一侧是 owner,这很重要,不然查询的表名就会变去。
正文完
 0
wujingquan
版权声明:本站原创文章,由 wujingquan 于2023-09-22发表,共计312字。
转载说明:Unless otherwise specified, all articles are published by cc-4.0 protocol. Please indicate the source of reprint.
评论(没有评论)