sequelize belongsTo hasOne hasMany 使用方法
文章目录
sequelize belongsTo hasOne hasMany 使用方法
一、一对一
eg:user表里有角色字段userRoleId对应角色表里的角色id
则存在,user表的userRoleId与role表的id一一对应关系
则
User.associate = function() {
app.model.User.belongsTo(app.model.Role, { foreignKey: 'userRoleId', targetKey: 'id', as: 'roleList'});
}只需要些再User model里即可
待续。。。
欢迎评论点赞支持,本人将不胜惶恐。本文由蜗牛老湿开发Butterfly发布

评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论