},
},
],
});
使用场景
1、给include 关联的表的数据排序
await person.findAll({
// 以关联表 comments 的 id..."
},
],
});
2、查询有子表数据的数据
也是比较常见的场景,比如返回有评论的用户数据,感知活跃的用户之类的
await person.findAll({
include: [...(
{
name: '修改过',
},
{
where: {
status: 3,
},
},
);
单个更新
查询出来的每个数据对象,都包含了update...person 操作 , 该 person 下 的comment 也会被一并删除
await person.destroy({
where: {
id: 10,
},
});
其中 onDelete...SET NULL: 从父表中删除或更新对应的行,同时将子表中的外键列设为空。注意,这些在外键列没有被设为NOT NULL时才有效。