Mysql FindAll,其中在sequelize中使用包含别名字段
如何使用别名include关联在何处执行FindAll 现在我有了这个代码: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
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
确保将联接
视为内部联接