Skip to content

[5.0.0-beta.14][Regression] mixed where clauses in include #10123

@madmoizo

Description

@madmoizo

What are you doing?

Nested where conditions are not related to their association.

const Sequelize = require('./')

const sequelize = new Sequelize({
  dialect: 'sqlite',
  file: ':memory:'
})

const Clientfile = sequelize.define('clientfile', {
  id: {
    type: Sequelize.UUID,
    defaultValue: Sequelize.UUIDV4,
    primaryKey: true
  }
})

const Mission = sequelize.define('mission', {
  id: {
    type: Sequelize.UUID,
    defaultValue: Sequelize.UUIDV4,
    primaryKey: true
  },
  startDate: {
    type: Sequelize.DATE
  }
})

const Building = sequelize.define('building', {
  id: {
    type: Sequelize.UUID,
    defaultValue: Sequelize.UUIDV4,
    primaryKey: true
  }
})

Clientfile.hasOne(Mission)
Clientfile.hasOne(Building)

const sync = async () => {
  await Clientfile.sync()
  await Mission.sync()
  await Building.sync()

  await Clientfile.findAll({
    attributes: [],
    include: [
      {
        association: 'mission',
        attributes: ['id'],
        where: {
          startDate: {
            [Sequelize.Op.gte]: new Date(),
            [Sequelize.Op.lte]: new Date()
          }
        }
      },
      {
        association: 'building',
        attributes: ['id']
      }
    ]
  })
}

sync()

What do you expect to happen?

The nested where condition is on mission association and should affect this association only

What is actually happening?

column building.startDate does not exist
The where condition of mission association seems to be applied to the building association.

Dialect: postgres
Sequelize version: 5.0.0-beta.14
Tested with latest release: Yes, 5.0.0-beta.15

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions