Ok, I’ve confirmed that simple User-Project examples from the docs work as expected. What seems to be a problem, however, is a self-referencing belongs-to-many relationship. Using the Person-Children example from the tests I tested this script:
var Sequelize = require('sequelize');
var db = new Sequelize('', '', '', {
host: 'localhost',
dialect: 'sqlite',
storage: ':memory:'
});
Person = db.define('Person', {
name: Sequelize.STRING
});
PersonChildren = db.define('PersonChildren', {
relationship: Sequelize.STRING
});
var Children = Person.belongsToMany(Person, {
as: 'Children',
through: PersonChildren
});
db.sync()
.then(function () {
return Promise.all([
Person.create({ name: 'John' }),
Person.create({ name: 'Mary' }),
Person.create({ name: 'Greg' })
])
.then(function (results) {
var john = results[0];
var mary = results[1];
var greg = results[2];
console.log('John:', john.get());
console.log('Mary:', mary.get());
return Promise.all([
john.addChildren(mary, {
relationship: 'is father of'
}),
john.addChildren(greg, {
relationship: 'is step-father to'
})
]);
});
})
.then(function () {
return Person.findAll({
where: {
name: 'John'
},
include: [
{
model: Person,
through: {
where: {
status: 'is father of'
}
}
}
]
})
.then(function (results) {
results.forEach(function (result) {
console.log(result.get());
});
});
})
.catch(console.stack);
But this leads to this error:
Unhandled rejection Error: Person is not associated to Person!
at validateIncludedElement (/Users/martialeagle/git/mumba/odyssey-backend-leave/node_modules/sequelize/lib/model.js:569:11)
Any thoughts on how to get that to work properly?