sequelize,hasMany,belongsTo 一对多关联笔记

文章发布于2020年10月21日 11:02, 归类于: Node.js

一对多关联

TeamModel.hasMany(PlayerModel)
PlayerModel.belongsTo(TeamModel);

创建团队和玩家。

let team = await TeamModel.create({ name: '小江' });
let player = await team.createPlayer({ color: '青色' });

创建团队,批量创建玩家。

let team = await TeamModel.create({name: '小狗'});

let players = await PlayerModel.bulkCreate([
  { color: '青色' },
  { color: '黑色' }
])

await team.addPlayers(players)

特殊方法

team.getPlayers()
team.countPlayers()
team.hasPlayer()
team.hasPlayers()
team.setPlayers()
team.addPlayer()
team.addPlayers()
team.removePlayer()
team.removePlayers()
team.createPlayer()

转载请注明来源:《 sequelize,hasMany,belongsTo 一对多关联笔记》- rojerYong's Blog

文章链接:https://www.eoway.cn /article/1603249360.html

如果此文摘取了你的原创,请联系本站管理员,将对此文修改、删除处理。

--END--
上一篇:sequelize,belongsToMany 多对多关联笔记 下一篇:sequelize,hasOne,belongsTo 一对一关联笔记