续集协会问题

时间:2016-04-15 09:32:50

标签: node.js sequelize.js

我在查询中有问题,当我们通过查找所有的(包括部分)条件时。

我的代码是

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数据,请不要计费。如果条件不匹配。

请帮助别人。

提前致谢。

1 个答案:

答案 0 :(得分:2)

使用BookingFeedbackMaster查询required: false。这样,您正在执行左外连接而不是内连接