You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When filtering for a foreign key value, using group_by and values, if "id" is in values, the group by fails to add the table name.
To Reproduce sql = await MyModel.filter(members__user_id=1).group_by('id').values('id').sql()
This will generate something like: SELECT "mymodel"."id" "id" FROM "mymodel" LEFT OUTER JOIN "mymodel_mymodeluser" ON "mymodel"."id"="mymodel_mymodeluser"."mymodel_id" LEFT OUTER JOIN "mymodeluser" ON "mymodel_mymodeluser"."mymodeluser_id"="mymodeluser"."id" WHERE "mymodeluser"."user_id"=1 GROUP BY "id"
If you execute that, it will fail with: tortoise.exceptions.OperationalError: column reference "id" is ambiguous
Expected behavior
Add the table name in the group by: SELECT "mymodel"."id" "id" FROM "mymodel" LEFT OUTER JOIN "mymodel_mymodeluser" ON "mymodel"."id"="mymodel_mymodeluser"."mymodel_id" LEFT OUTER JOIN "mymodeluser" ON "mymodel_mymodeluser"."mymodeluser_id"="mymodeluser"."id" WHERE "mymodeluser"."user_id"=1 GROUP BY "mymodel"."id"
The text was updated successfully, but these errors were encountered:
Describe the bug
When filtering for a foreign key value, using group_by and values, if "id" is in values, the group by fails to add the table name.
To Reproduce
sql = await MyModel.filter(members__user_id=1).group_by('id').values('id').sql()
This will generate something like:
SELECT "mymodel"."id" "id" FROM "mymodel" LEFT OUTER JOIN "mymodel_mymodeluser" ON "mymodel"."id"="mymodel_mymodeluser"."mymodel_id" LEFT OUTER JOIN "mymodeluser" ON "mymodel_mymodeluser"."mymodeluser_id"="mymodeluser"."id" WHERE "mymodeluser"."user_id"=1 GROUP BY "id"
If you execute that, it will fail with:
tortoise.exceptions.OperationalError: column reference "id" is ambiguous
Expected behavior
Add the table name in the group by:
SELECT "mymodel"."id" "id" FROM "mymodel" LEFT OUTER JOIN "mymodel_mymodeluser" ON "mymodel"."id"="mymodel_mymodeluser"."mymodel_id" LEFT OUTER JOIN "mymodeluser" ON "mymodel_mymodeluser"."mymodeluser_id"="mymodeluser"."id" WHERE "mymodeluser"."user_id"=1 GROUP BY "mymodel"."id"
The text was updated successfully, but these errors were encountered: