0

I tried to put a custom condition on included model's column to be equal to value of parent model column but it is not working as expected in sequelize 3.8.7 module. Below is the code i tried

Quotes.findOne({
     where: {'id' : req.body.quoteId},
     include : [
      {model : Jobs},  
      {model : HaulerProfiles, include : [{model : UserFavouriteBanned, where : {'userId' : mysqlORM.sequelize.col('Job.customerId'), 'actionOn' : mysqlORM.sequelize.col('HaulerProfile.id'), 'actionType' : 'B'}, required : false}]}

   ]

})

But when i check executed query conditions are not included with mysqlORM.sequelize.col. It execute LEFT OUTER JOIN Like this

LEFT OUTER JOIN `UserFavouriteBanned` AS `HaulerProfile.UserFavouriteBanned` ON `HaulerProfile`.`id` = `HaulerProfile.UserFavouriteBanned`.`actionOn` AND `Job`.`customerId` AND `HaulerProfile`.`id` AND `HaulerProfile.UserFavouriteBanned`.`actionType` = 'B'

Please help so i can put conditions on column value of included model.

Rajendra Khabiya
  • 1,990
  • 2
  • 22
  • 39

1 Answers1

0

Change required: false to required: true. This will return only rows whose included rows match your conditions.

Tom Jardine-McNamara
  • 2,418
  • 13
  • 24