1
У меня есть 2 модели пользователь и пункт с многим ко многим отношений, вот определение:Sequelize FindAll где многие ко многим критериям
User = sequelize.define('User', {
name: {type: Sequelize.STRING}
})
Item = sequelize.define('Item', {
name: {
type: Sequelize.STRING,
allowNull: false
}
}
User.belongsToMany(models.Item, {
as: 'items',
through: 'UserItem'
})
Item.belongsToMany(models.User, {
as: 'owners',
through: 'UserItem'
})
И моя просьба:
Item.findAll({
include: [{
model: User,
through: {
where: {id: 2}
}
}]
}).then(items => {
log.debug(items)
}).catch(err => {
log.error(err)
})
Тогда у меня есть : Error: User is not associated to Item!
Я также попробовать это:
Item.findAll({
where: {'owners.id': 2},
include: Item.assocations.owners
}).then(items => {
debug(items)
}).catch(err => {
log.error(err)
})
Но теперь у меня есть Error: SQLITE_ERROR: no such column: Item.owners.id
Любые идеи?