sequelize-typescript icon indicating copy to clipboard operation
sequelize-typescript copied to clipboard

Including models without predefined schema fails if it's a separate query

Open Mustachipleb opened this issue 2 years ago • 0 comments

Issue

Versions

  • sequelize: 6.32.1
  • sequelize-typescript: 2.1.5
  • typescript: 4.7.4
  • tedious: 11.8.0

Issue type

  • [x] bug report
  • [ ] feature request

Actual behavior

It is impossible to include a model on a specific schema to a query on another model if the query is marked as separate.

Expected behavior

It is possible to include a model from a specific schema to a query on another model if the query is marked as separate.

Steps to reproduce

const schemaIWantToUse = 'dbo';
const result = await MyModel.findAll({
    include: [
        {
            model: MyOtherModel.schema(schemaIWantToUse),
            separate: true
        }
    ]
});

Query model X and include model Y on any schema (eg dbo) and mark it as separate. The query will fail, because the resulting SQL will have (roughly, without sequelize sugar) this structure:

SELECT * FROM [MyTable]
JOIN [MyOtherTable] ON [MyTable].[myOtherTableId] = [MyOtherTable].[id]

SequelizeDatabaseError: Invalid object name 'myOtherTable'.

Mustachipleb avatar Jul 27 '23 12:07 Mustachipleb