Repository navigation
Open
Labels
pending-approvalBug reports that have not been verified yet, or feature requests that have not been accepted yet
Description
Issue Creation Checklist
- [ Y] I understand that my issue will be automatically closed if I don't fill in the requested information
- [ Y] I have read the contribution guidelines
Bug Description
Postgresql Join with Schema is giving error
const todosWithUsers = await Todo.findAll({
include: [
{
model: User,
as: 'user', // Use the same alias
attributes: ['username', 'email']
}
],
limit: 20
});
is generating SQL query as
SELECT
"Todo"."id",
"Todo"."title",
"Todo"."description",
"Todo"."status",
"Todo"."userId",
"Todo"."createdAt",
"Todo"."updatedAt",
"user"."id" AS "user.id",
"user"."username" AS "user.username",
"user"."email" AS "user.email"
FROM "test_schema"."Todo" AS "Todo"
LEFT OUTER JOIN "test_schema"."User" AS "user"
ON "test_schema"."Todo"."userId" = "user"."id"
ORDER BY "Todo"."id"
LIMIT 20;
Instead of
SELECT
"Todo"."id",
"Todo"."title",
"Todo"."description",
"Todo"."status",
"Todo"."userId",
"Todo"."createdAt",
"Todo"."updatedAt",
"user"."id" AS "user.id",
"user"."username" AS "user.username",
"user"."email" AS "user.email"
FROM "test_schema"."Todo" AS "Todo"
LEFT OUTER JOIN "test_schema"."User" AS "user"
ON "Todo"."userId" = "user"."id"
ORDER BY "Todo"."id"
LIMIT 20;
Key difference is
ON "test_schema"."Todo"."userId" = "user"."id"
ON "Todo"."userId" = "user"."id"
Having ON "test_schema"."Todo"."userId" = "user"."id" is giving error as below
ERROR: invalid reference to FROM-clause entry for table "Todo"
There is an entry for table "Todo", but it cannot be referenced from this part of the query.
SQL state: 42P01
Detail: There is an entry for table "Todo", but it cannot be referenced from this part of the query.
Character: 459
Reproducible Example
Here is the link to the SSCCE for this issue:
What do you expect to happen?
When JOIN is present in the SQL and if the table is already aliased , then it should use alias in the JOIN ON
What is actually happening?
When JOIN is present in the SQL and if the table is already aliased , Instead of alias, "SCHEMA"."TABLE"."COLUMN" is being used in the JOIN ON
Environment
- Sequelize version: v7 aplha
- Node.js version: v22
- If TypeScript related: TypeScript version: NO
- Database & Version: Postgresql 17
- Connector library & Version: "@sequelize/postgres": "^7.0.0-alpha.46",
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.
Reacted by k02pradeepwork
Metadata
Metadata
Assignees
Labels
pending-approvalBug reports that have not been verified yet, or feature requests that have not been accepted yet
Activity