typeorm icon indicating copy to clipboard operation
typeorm copied to clipboard

test: add test which demonstrates incorrect JOIN clause for issue 1668

Open sgronblo opened this issue 6 years ago • 4 comments

Note: no fix here yet, just a new test case that demonstrates breakage when getting a relation using find when using postgres. Not tested on other DBs.

It gets a bit hairy to see what's going on as I tried to boil away anything that was related to the original problem domain. However you can make the query work by changing the following in the broken query:

ON C__a.aId="C"."aId" -> ON "C__a"."id"="C"."aId"

So, two problems. Double quotes are missing, and the id column is incorrect.

-- Original commit message follows

The problem demonstrated here is not exactly the same as in the original issue for 1668. However the symptoms are similar. The original creator of 1668 was experiencing a lack of double quotes around the table/column name for a join condition. That matches this case. However there is an additional problem where the column used to join to the related table is also incorrect.

When running the tests, and viewing the database logs you can see the following error:

2019-09-23 08:45:08.233 UTC [6013] ERROR: missing FROM-clause entry for table "c__a" at character 178 2019-09-23 08:45:08.233 UTC [6013] STATEMENT: SELECT "C"."aId" AS "C_aId", "C"."fooCode" AS "C_fooCode", "C"."barId" AS "C_barId", "C__a"."id" AS "C__a_id", "C__a"."name" AS "C__a_name" FROM "c" "C" LEFT JOIN "a" "C__a" ON C__a.aId="C"."aId" WHERE "C"."barId" = $1

Test for #1668

sgronblo avatar Sep 23 '19 08:09 sgronblo

Rebased & cleaned up the test a bit.

imnotjames avatar Oct 10 '20 05:10 imnotjames

Is this still an issue?

hinogi avatar Aug 05 '23 20:08 hinogi

This is still an issue in 0.3.17.

EDIT: For me, it started working when I added an @JoinTable annotation with name, joinColumn and inverseJoinColumn on both ends of the ManyToMany relation.

aphofstede avatar Sep 21 '23 18:09 aphofstede

If you need to fix this issue or want to test the solution, install #11400

yevhen-komarov avatar May 16 '25 10:05 yevhen-komarov