Skip to content
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

SQL joins not working properly when database schema is provided when creating Sequelize instance (ibmi dialect) #17376

Open
3 of 6 tasks
vincentB23 opened this issue Jun 10, 2024 · 0 comments
Labels
pending-approval Bug reports that have not been verified yet, or feature requests that have not been accepted yet type: bug

Comments

@vincentB23
Copy link

Issue Creation Checklist

  • I understand that my issue will be automatically closed if I don't fill in the requested information
  • I have read the contribution guidelines

Bug Description

Sequelize generates a wrong SQL statement when the schema property is defined when the Sequelize instance is generated. When I remove the schema property from the Sequelize instance itself, and instead add the schema to the initialization of each model, it works correctly.

SQL generated when using schema property in the Sequelize instance (and NOT on Model initialization): WRONG

SELECT
    "Broker"."COSCDE" AS "id",
    "auxiliary_broker"."COPCOU" AS "auxiliary_broker.id"
FROM
    "TA2DTA"."COS" AS "Broker"
    LEFT OUTER JOIN "TA2DTA"."COP" AS "auxiliary_broker" ON "TA2DTA"."Broker"."COSCDE" = "auxiliary_broker"."COPCOU"
WHERE
    "Broker"."COSCDE" = 11
ORDER BY
    "auxiliary_broker"."COPNEW" DESC,
    "auxiliary_broker"."COPPTF" DESC FETCH NEXT 10 ROWS ONLY;

SQL generated when using schema property in the initialization of each model (and NOT on Sequelize instance): CORRECT

SELECT
    "Broker"."COSCDE" AS "id",
    "auxiliary_broker"."COPCOU" AS "auxiliary_broker.id"
FROM
    "TA2DTA"."COS" AS "Broker"
    LEFT OUTER JOIN "TA2DTA"."COP" AS "auxiliary_broker" ON "Broker"."COSCDE" = "auxiliary_broker"."COPCOU"
WHERE
    "Broker"."COSCDE" = 11
ORDER BY
    "auxiliary_broker"."COPNEW" DESC,
    "auxiliary_broker"."COPPTF" DESC FETCH NEXT 10 ROWS ONLY;

Reproducible Example

Here is the link to the SSCCE for this issue:

What do you expect to happen?

Using one schema property for the whole instance, or one for each model should not make any difference in the SQL output generated by sequelize. I expect in both cases to see the working SQL output (code block 2)

What is actually happening?

Sequelize generates an incorrect SQL JOIN statement when using the Sequelize instance schema property

Environment

  • Sequelize version: 7.0.0-alpha.41
  • Node.js version: 18.20.3
  • If TypeScript related: TypeScript version:
  • Database & Version: db2
  • Connector library & Version: ibmi

Would you be willing to resolve this issue by submitting a Pull Request?

  • Yes, I have the time and I know how to start.
  • Yes, I have the time but I will need guidance.
  • No, I don't have the time, but my company or I are supporting Sequelize through donations on OpenCollective.
  • No, I don't have the time, and I understand that I will need to wait until someone from the community or maintainers is interested in resolving my issue.

Indicate your interest in the resolution of this issue by adding the 👍 reaction. Comments such as "+1" will be removed.

@vincentB23 vincentB23 added pending-approval Bug reports that have not been verified yet, or feature requests that have not been accepted yet type: bug labels Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending-approval Bug reports that have not been verified yet, or feature requests that have not been accepted yet type: bug
Projects
None yet
Development

No branches or pull requests

1 participant