我想在包含模型的情况下使用where条件,但它不起作用......
我的代码:
return this.context.OfferType.findAll({
include: [{
model: this.context.Offer,
where: Sequelize.or(["description like '%"+search+"%'"],["name like '%"+search+"%'"]),
include: [{
model: this.context.OfferStore
}]
}]
});
我生成的查询:
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`;
Name
位于OfferStore
表中,description
位于Offers
表中。