Mysql FindAll,其中在sequelize中使用包含别名字段

Mysql FindAll,其中在sequelize中使用包含别名字段,mysql,node.js,express,sequelize.js,Mysql,Node.js,Express,Sequelize.js,如何使用别名include关联在何处执行FindAll 现在我有了这个代码: Photobook.findAndCountAll({ include: [ { attributes: ['full_name'], as: 'layouter_name', model: UserModel, }, { attributes: ['full_name'], as: 'curr

如何使用别名include关联在何处执行FindAll

现在我有了这个代码:

 Photobook.findAndCountAll({
    include: [
      {
        attributes: ['full_name'],
        as: 'layouter_name',
        model: UserModel,
      },
      {
        attributes: ['full_name'],
        as: 'current_pic',
        model: UserModel,
      }
    ],
    where:{
       {
         '$current_pic.full_name$' : {
             $like: '%name%'
         }
      }
    }
 });
由于Photobook模型没有
当前图片全名
字段,因此它不起作用。我只想搜索
current\u pic
关联,而不是
layouter\u name
关联

如何执行类似操作?

尝试以下操作:

Photobook.findAndCountAll({
    include: [
      {
        attributes: ['full_name'],
        as: 'layouter_name',
        model: UserModel,
      },
      {
        attributes: ['full_name'],
        as: 'current_pic',
        model: UserModel,
        where: {
            full_name: {
                $like: '%name%'
            }
        },
        required: true
      }
    ]
 }); 
您可以在
include
数组本身中给出where条件
required:true
确保将
联接
视为
内部联接

尝试以下操作:

Photobook.findAndCountAll({
    include: [
      {
        attributes: ['full_name'],
        as: 'layouter_name',
        model: UserModel,
      },
      {
        attributes: ['full_name'],
        as: 'current_pic',
        model: UserModel,
        where: {
            full_name: {
                $like: '%name%'
            }
        },
        required: true
      }
    ]
 }); 
您可以在
include
数组本身中给出where条件
required:true
确保将
联接
视为
内部联接