当在子数组中使用“where”和“in”时,会产生错误

这是我的模型定义:

var Tag = sequelize.define('Tag', { name: Sequelize.STRING }); var Event = sequelize.define('Event', { name: Sequelize.STRING, }); Event.hasMany(Tag, {as: 'tags', through: 'event_tags', foreignKey: 'eventId'}); Tag.hasMany(Event, {as: 'events', through: 'event_tags', foreignKey: 'tagId'}); 

换句话说就是:有事件和标签。 事件标有许多标签。

我试图运行这个查询:

 Event .findAndCountAll({ include: [{model: Tag, as: 'tags'}], where: {'tags.id': {in: [1,2,3,4]}}, order: order, limit: pageSize, offset: pageSize * (page - 1), }) .success(function(result) { ... }); 

但是我得到这个错误:

  \node_modules\sequelize\lib\dialects\abstract\query-generator.js:1134 var logicResult = Utils.getWhereLogic(logic, hash[key][logic]); ^ TypeError: Cannot read property 'in' of undefined 

我究竟做错了什么?

我在“in”expression式之前使用过,例如:

  Tag .find({ where: {id: {in: [1,2,3,4]}} }).success(...) 

它工作得很好。

尽pipe如此,我从来没有在子expression式中使用过expression式。 所以我不知道这是否正确的做法。

不需要“在”属性,继续自动定义这个。 只需设置数组。

 Tag.find({ where: { id: [1,2,3,4] } }).success(...)