-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
[Bug] Nested includes with scopes & field names SQL errors #4210
Copy link
Copy link
Closed
Description
When updating from v3.3.0 to v3.5.1, I found that several queries were no longer working as intended, now throwing out SQL Errors. After doing a bit of bisecting, I found the source of the problem to be commit 538a095.
Here is my best estimation at providing a replicable test case, let me know if my pseudo doesn't recreate the issue on your side!
var Foo = sequelize.define('Foo');
var Bar = sequelize.define('Bar');
var Baz = sequelize.define('Baz', {
qux: {
type: Sequelize.INTEGER,
field: 'quxId'
}
}, {
scopes: {
quxScope: {
where: {
qux: 1
}
}
}
});
Foo.belongsToMany(Bar);
Bar.belongsToMany(Foo);
Bar.hasMany(Baz);
Baz.belongsTo(Bar);
Foo.find({
include: [{
model: Bar,
include: Baz.scope('quxScope')
}]
});Which produces an error along the lines of:
Unhandled rejection SequelizeDatabaseError: Invalid column name 'qux'.
In my case, it appears that Sequelize tried to alias the column like [Bar.Baz.quxId] AS [Bar.Baz.qux] but in the outer WHERE clause it attempts to add the quxScope and references the column as [Bar.Baz].[qux].
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels