Sequelize.js Sequelize排除属于许多映射对象
当对一个对象进行SequelizeJS查询并包含一个具有“属于多个关联”的关系时,有没有办法使included属性不返回带有结果的关联映射对象 i、 e:Sequelize.js Sequelize排除属于许多映射对象,sequelize.js,Sequelize.js,当对一个对象进行SequelizeJS查询并包含一个具有“属于多个关联”的关系时,有没有办法使included属性不返回带有结果的关联映射对象 i、 e: Users.findAll({include:[{model:Role,as:'roles'}]}) //生成以下形式的对象 用户:{ 用户名:“测试”, 角色:[ { 名称:“用户”, UserRoles:{userId:1,roleId:1}/您可以尝试指定属性属性 所以要包括字段,比如你加的a,b,c attributes: ['a',
Users.findAll({include:[{model:Role,as:'roles'}]})
//生成以下形式的对象
用户:{
用户名:“测试”,
角色:[
{
名称:“用户”,
UserRoles:{userId:1,roleId:1}/您可以尝试指定属性
属性
所以要包括字段,比如你加的a,b,c
attributes: ['a', 'b','c']
排除他们
attributes:{exclude:['a', 'b','c']}
芬德尔看起来像
Model.someModel.findAll({
where: // some condition
include: // some other model
attributes: // some fields
})
您还可以在include子句中指定属性在github注释中找到了解决方案:
要点:
Users.findAll({
包括:[
{
模式:角色,
作为‘角色’,
通过:{attributes:[]}//尝试了您的响应,它没有排除加入object的UserRoles。现在,我只是使用一个映射并在发送到客户端之前从结果中删除UserRoles对象。
Model.someModel.findAll({
where: // some condition
include: // some other model
attributes: // some fields
})
Users.findAll({
include: [
{
model: Role,
as: 'roles',
through: {attributes: []} //<-- this line will prevent mapping object from being added
}
]
});