New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Nested includes with scopes & field names SQL errors #4210

Closed
ackerdev opened this Issue Jul 29, 2015 · 0 comments

Comments

1 participant
@ackerdev
Contributor

ackerdev commented Jul 29, 2015

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].

@janmeier janmeier closed this in 8eb2cf1 Jul 29, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment