-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Description
Steps to reproduce or a small repository showing the problem:
-
Create two entities that don't follow the naming convention (ex.
Thingin tablethingsandTagin tabletags) -
Create a join table for them (
thing_tags) (note that due to the departure from naming convention earlier, this is also a departure from naming convention) -
Create a
@ManyToManyrelation using@JoinTableinsideThingas follows:
@ManyToMany(type => Tag, {eager: true})
@JoinTable({
name: "thing_tags",
joinColumn: {name: "thing_id", referencedColumnName: "id"}
inverseJoinColumn: {name: "tag_id", referencedColumnName: "id"}
})
tags: Tag[];When trying to retrieve a Thing, the query is just barely wrong:
SELECT Thing_tags_relation_id.tag_id AS "tag_id", Thing_tags_relation_id.thing_id AS "thing_id" FROM "tags" "tags" INNER JOIN "thing_tags" "Thing_tags_relation_id" ON (Thing_tags_relation_id.thing_id = $1 AND Thing_tags_relation_id.tag_id = "tags"."id") ORDER BY Thing_tags_relation_id.tag_id ASC, Thing_tags_relation_id.thing_id ASC;
ERROR: missing FROM-clause entry for table "thing_tags_relation_id"The problem here is that Thing_tags_relation_id is not quoted everywhere it's mentioned. If I take the query to postgres, and add quotes around every unquoted Thing_tags_relation_id, the query works great:
db_test=# SELECT "Thing_tags_relation_id".tag_id AS "tag_id", "Thing_tags_relation_id".thing_id AS "thing_id" FROM "tags" "tags" INNER JOIN "thing_tags" "Thing_tags_relation_id" ON ("Thing_tags_relation_id".thing_id = 1743 AND "Thing_tags_relation_id".tag_id = "tags". "id") ORDER BY "Thing_tags_relation_id".tag_id ASC, "Thing_tags_relation_id".thing_id ASC;
tag_id | thing_id
--------+-----------
(0 rows)PS I personally would love a parametrizedQuery parameter in error reports that prints the complete query with params filled out (exactly as it would have been sent).
As always thanks for all the work on typeorm, it is 100% improving the development lives of me and my team :)