1

I'd like to use the where conditions on including models but it doesn't work...

My code :

return this.context.OfferType.findAll({
 include: [{
   model: this.context.Offer,
   where: Sequelize.or(["description like '%"+search+"%'"],["name like '%"+search+"%'"]),
   include: [{
     model: this.context.OfferStore
   }]
 }]
});

My generated query :

SELECT `OfferType`.`id`, `OfferType`.`name`, `OfferType`.`createdAt`, `OfferType`.`updatedAt`, `Offers`.`id` AS `Offers.id`, `Offers`.`startDate` AS `Offers.startDate`, `Offers`.`endDate` AS `Offers.endDate`, `Offers`.`conditions` AS `Offers.conditions`, `Offers`.`description` AS `Offers.description`, `Offers`.`createdAt` AS `Offers.createdAt`, `Offers`.`updatedAt` AS `Offers.updatedAt`, `Offers`.`OfferTypeId` AS `Offers.OfferTypeId`, `Offers`.`OfferCategoryId` AS `Offers.OfferCategoryId`, `Offers`.`OfferStoreId` AS `Offers.OfferStoreId`, `Offers.OfferStore`.`id` AS `Offers.OfferStore.id`, `Offers.OfferStore`.`name` AS `Offers.OfferStore.name`, `Offers.OfferStore`.`logo` AS `Offers.OfferStore.logo`, `Offers.OfferStore`.`presentation` AS `Offers.OfferStore.presentation`, `Offers.OfferStore`.`mobilePhone` AS `Offers.OfferStore.mobilePhone`, `Offers.OfferStore`.`fixedLinePhone` AS `Offers.OfferStore.fixedLinePhone`, `Offers.OfferStore`.`fax` AS `Offers.OfferStore.fax`, `Offers.OfferStore`.`email` AS `Offers.OfferStore.email`, `Offers.OfferStore`.`website` AS `Offers.OfferStore.website`, `Offers.OfferStore`.`openingHours` AS `Offers.OfferStore.openingHours`, `Offers.OfferStore`.`createdAt` AS `Offers.OfferStore.createdAt`, `Offers.OfferStore`.`updatedAt` AS `Offers.OfferStore.updatedAt` FROM `OfferTypes` AS `OfferType` INNER JOIN `Offers` AS `Offers` ON `OfferType`.`id` = `Offers`.`OfferTypeId` AND (description like '%sport%' OR name like '%sport%') LEFT OUTER JOIN `OfferStores` AS `Offers.OfferStore` ON `Offers.OfferStore`.`id` = `Offers`.`OfferStoreId`;

Nameis in the OfferStore table and description in the Offers table.

2
  • Did you find a solution to this? I want to achieve the exact same thing which is pretty standard for search but there doesn't seem to be anyone about for help with this stuff. Commented May 19, 2016 at 13:52
  • Found a half-solution that would work in this case. See: stackoverflow.com/questions/31258158/… Commented May 19, 2016 at 14:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.