如何使用Alias inscom incomecsion
执行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_pic.full_name
字段。我只想搜索current_pic
关联而不是layouter_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
数组本身中给出条件。required: true
确保JOIN
被视为INNER JOIN