Repository navigation
Description
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
Reproducible Example
When forming a query to a model, a communication error: "missing FROM-clause entry for table "fk1_Parents_Sketches"", occurs if you set a record limit
Sketches.findAll({ order: queryOrder, limit: length, offset: start, where: { '$fk1_Parents_Sketches.id$': null }, include: [ { model: Sketches, as: 'fk1_Parents_Sketches', attributes: [], required: false } ] })
When you add "limit" to a query, sequalize breaks the query
What do you expect to happen?
I would like to see a query without a subquery, just to put a limit value at the end of the query
SELECT "Sketches"."id", "fk1_Parents_Sketches->childSketches_parentSketches"."parentId" AS "fk1_Parents_Sketches.childSketches_parentSketches.parentId", "fk1_Parents_Sketches->childSketches_parentSketches"."childId" AS "fk1_Parents_Sketches.childSketches_parentSketches.childId" FROM "Sketches" AS "Sketches" LEFT OUTER JOIN ( "childSketches_parentSketches" AS "fk1_Parents_Sketches->childSketches_parentSketches" INNER JOIN "Sketches" AS "fk1_Parents_Sketches" ON "fk1_Parents_Sketches"."id" = "fk1_Parents_Sketches->childSketches_parentSketches"."parentId" ) ON "Sketches"."id" = "fk1_Parents_Sketches->childSketches_parentSketches"."childId" WHERE "fk1_Parents_Sketches"."id" IS NULL LIMIT '10' OFFSET 0;
What is actually happening?
SELECT "Sketches".*, "fk1_Parents_Sketches->childSketches_parentSketches"."parentId" AS "fk1_Parents_Sketches.childSketches_parentSketches.parentId", "fk1_Parents_Sketches->childSketches_parentSketches"."childId" AS "fk1_Parents_Sketches.childSketches_parentSketches.childId" FROM ( SELECT "Sketches"."id" FROM "Sketches" AS "Sketches" WHERE "fk1_Parents_Sketches"."id" IS NULL LIMIT '10' OFFSET 0 ) AS "Sketches" LEFT OUTER JOIN ( "childSketches_parentSketches" AS "fk1_Parents_Sketches->childSketches_parentSketches" INNER JOIN "Sketches" AS "fk1_Parents_Sketches" ON "fk1_Parents_Sketches"."id" = "fk1_Parents_Sketches->childSketches_parentSketches"."parentId" ) ON "Sketches"."id" = "fk1_Parents_Sketches->childSketches_parentSketches"."childId"
Environment
- Sequelize version: 6.37.3
- Node.js version: 20.11.1
- If TypeScript related: TypeScript version:
- Database & Version: PostgreSQL 16.1
- Connector library & Version: pg 8.11.3
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.
Activity
wadeharrell commentedon Oct 24, 2024
following the example from https://sequelize.org/docs/v6/advanced-association-concepts/eager-loading/#complex-where-clauses-at-the-top-level but adding a limit:
Will generate broken SQL using 6.37.4
WikiRik commentedon Oct 25, 2024
This might be related to #12971 I think?