Sequelize 关联问题
Sequelize associations issue
我在查询中遇到问题,当我们在查找全部(包括部分)中传递 where 条件时。
我的密码是
db.Doctor.findAll({
attributes : ['id','firstName','lastName',
'profilePicture','education','experience',
'fees','gender','mobile','email'],
include: [
{ model : db.Category, attributes : ['title']},
{ model : db.Area, attributes : ['name']},
{ model : db.City, attributes : ['name']},
{ model : db.State, attributes : ['name']},
{ model : db.Country, attributes : ['name']},
{ model : db.DoctorClinicPicture, attributes : ['imagePath']},
{
model : db.BookingFeedbackMaster,
attributes : ['rating','comment'],
where : { status: 1 }
}
],
where : { id: req.query.doctorId},
order: 'id ASC'
}).then(function(data){
if (data != null )
{
res.json({status:true,msg:"Doctor viewed successfully!!",data:data});
}
else
{
res.json({status:true,msg:"Doctor is temporary not available",data:""});
}
}).catch(function(err){
res.json({status:"fail"});
});
如果 BookingFeedbackMaster 中存在任何状态为 1 的行,它会很好地工作,否则它不会给我任何输出。
我需要获取其他数据。如果我没有获得 BookingFeedbackMaster 数据,则没有仪表。如果条件不匹配。
请帮助某人。
提前致谢。
用required: false
查询BookingFeedbackMaster
。这样,您执行的是左外连接而不是内连接
我在查询中遇到问题,当我们在查找全部(包括部分)中传递 where 条件时。
我的密码是
db.Doctor.findAll({
attributes : ['id','firstName','lastName',
'profilePicture','education','experience',
'fees','gender','mobile','email'],
include: [
{ model : db.Category, attributes : ['title']},
{ model : db.Area, attributes : ['name']},
{ model : db.City, attributes : ['name']},
{ model : db.State, attributes : ['name']},
{ model : db.Country, attributes : ['name']},
{ model : db.DoctorClinicPicture, attributes : ['imagePath']},
{
model : db.BookingFeedbackMaster,
attributes : ['rating','comment'],
where : { status: 1 }
}
],
where : { id: req.query.doctorId},
order: 'id ASC'
}).then(function(data){
if (data != null )
{
res.json({status:true,msg:"Doctor viewed successfully!!",data:data});
}
else
{
res.json({status:true,msg:"Doctor is temporary not available",data:""});
}
}).catch(function(err){
res.json({status:"fail"});
});
如果 BookingFeedbackMaster 中存在任何状态为 1 的行,它会很好地工作,否则它不会给我任何输出。
我需要获取其他数据。如果我没有获得 BookingFeedbackMaster 数据,则没有仪表。如果条件不匹配。
请帮助某人。
提前致谢。
用required: false
查询BookingFeedbackMaster
。这样,您执行的是左外连接而不是内连接