-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Closed
Description
Consider the code below, which shows a mistake in which the wrong alias is given:
const Sequelize = require('sequelize');
const sequelize = new Sequelize({ dialect: 'sqlite', storage: 'db.sqlite' });
const Foo = sequelize.define("foo", { name: Sequelize.STRING });
const Bar = sequelize.define("bar", { name: Sequelize.STRING });
Foo.hasMany(Bar, { as: "some_alias" });
sequelize.sync()
.then(() => Foo.create({ name: "foo" }))
.then(() => Bar.create({ name: "bar", fooId: 1 }))
.then(() => Foo.findAll({
include: {
model: Bar,
as: "wrong_alias"
}
}))
.then(result => {
console.log(JSON.stringify(result, null, 4));
});Sequelize throws the following error:
SequelizeEagerLoadingError: bar is associated to foo using an alias. You've included an alias (wrong_alias), but it does not match the alias defined in your association.
It is already great that it includes the wrong alias in the error message, but it would be even more helpful if the correct alias(es) were also given in the error message. Something like:
SequelizeEagerLoadingError: bar is associated to foo using an alias. You've included an alias (wrong_alias), but it does not match the alias(es) defined in your association (some_alias).
Metadata
Metadata
Assignees
Labels
No labels