Monday, 1 May 2017

Sequlize include even if it's null

am using Sequlize express with nodejs backend

some of my sequelize i need to include with another table

some of these data is null , so the whole result will be null

my question is: how can i return the some if data it's available and return the other null if not there

router.get("/scheduled/:id",function (req,res,next) {

models.Order.findOne({

    where: {

        id: req.params.id



    },attributes: ['orderStatus','id','serviceId','orderDescription','orderScheduledDate'],
    include: [
        {model: models.User,
        attributes: ['firstName','phoneNumber']
        }
    ]
}).then(function(data) {

    res.status(200).send({data : data,serviceName : data["serviceId"]});

});

});

the result will return null if there is no user for the order !! i want to return the order details and user is null

thnx



via Faisal

No comments:

Post a Comment