From 1479366aab9754a3d3e168962c1143876fead43a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ad=C3=A1mek?= Date: Tue, 8 Dec 2020 21:07:38 +0100 Subject: [PATCH] fix(sql): use `__` when aliasing fetch-joined properties Previously fetch-joining failed when there was a conflict in aliased property name and parent entity property name and the alias is same as the parent property name (e.g. property `Book.author` and alias `author`). Related #1171 --- packages/knex/src/AbstractSqlDriver.ts | 10 +++---- packages/knex/src/query/QueryBuilder.ts | 3 +- tests/EntityManager.sqlite2.test.ts | 4 +-- tests/QueryBuilder.test.ts | 4 +-- tests/issues/GH1041.test.ts | 4 +-- tests/issues/GH1171.test.ts | 5 ++-- tests/joined-strategy.postgre.test.ts | 40 ++++++++++++------------- 7 files changed, 35 insertions(+), 35 deletions(-) diff --git a/packages/knex/src/AbstractSqlDriver.ts b/packages/knex/src/AbstractSqlDriver.ts index c9a85dd83191..fad7111d0bb4 100644 --- a/packages/knex/src/AbstractSqlDriver.ts +++ b/packages/knex/src/AbstractSqlDriver.ts @@ -110,7 +110,7 @@ export abstract class AbstractSqlDriver meta2.properties[pk].fieldNames.every(name => { - return Utils.isDefined(root![`${relationAlias}_${name}`], true); + return Utils.isDefined(root![`${relationAlias}__${name}`], true); })); if (!hasPK) { @@ -122,9 +122,9 @@ export abstract class AbstractSqlDriver { if (prop.fieldNames.length > 1) { // composite keys relationPojo[prop.name] = prop.fieldNames.map(name => root![`${relationAlias}_${name}`]); - prop.fieldNames.map(name => delete root![`${relationAlias}_${name}`]); + prop.fieldNames.map(name => delete root![`${relationAlias}__${name}`]); } else { - const alias = `${relationAlias}_${prop.fieldNames[0]}`; + const alias = `${relationAlias}__${prop.fieldNames[0]}`; relationPojo[prop.name] = root![alias]; delete root![alias]; } @@ -480,13 +480,13 @@ export abstract class AbstractSqlDriver>(qb: QueryBuilder, prop: EntityProperty, tableAlias?: string): Field[] { if (prop.formula) { const alias = qb.ref(tableAlias ?? qb.alias).toString(); - const aliased = qb.ref(tableAlias ? `${tableAlias}_${prop.fieldNames[0]}` : prop.fieldNames[0]).toString(); + const aliased = qb.ref(tableAlias ? `${tableAlias}__${prop.fieldNames[0]}` : prop.fieldNames[0]).toString(); return [`${prop.formula!(alias)} as ${aliased}`]; } if (tableAlias) { - return prop.fieldNames.map(fieldName => qb.ref(fieldName).withSchema(tableAlias).as(`${tableAlias}_${fieldName}`)); + return prop.fieldNames.map(fieldName => qb.ref(fieldName).withSchema(tableAlias).as(`${tableAlias}__${fieldName}`)); } return prop.fieldNames; diff --git a/packages/knex/src/query/QueryBuilder.ts b/packages/knex/src/query/QueryBuilder.ts index 3172e5fa2c5a..054252aa2d96 100644 --- a/packages/knex/src/query/QueryBuilder.ts +++ b/packages/knex/src/query/QueryBuilder.ts @@ -144,8 +144,7 @@ export class QueryBuilder = AnyEntity> { protected getFieldsForJoinedLoad>(prop: EntityProperty, alias: string): Field[] { const fields: Field[] = []; - const meta2 = this.metadata.find(prop.type)!; - meta2.props + prop.targetMeta!.props .filter(prop => this.driver.shouldHaveColumn(prop, this._populate)) .forEach(prop => fields.push(...this.driver.mapPropToFieldNames(this as unknown as QueryBuilder, prop, alias))); diff --git a/tests/EntityManager.sqlite2.test.ts b/tests/EntityManager.sqlite2.test.ts index 3711da2608e5..ca9ca948b4e6 100644 --- a/tests/EntityManager.sqlite2.test.ts +++ b/tests/EntityManager.sqlite2.test.ts @@ -924,8 +924,8 @@ describe('EntityManagerSqlite2', () => { .leftJoinAndSelect('b.tags', 't') .where({ 't.name': ['sick', 'sexy'] }); const sql = 'select `a`.*, ' + - '`b`.`id` as `b_id`, `b`.`created_at` as `b_created_at`, `b`.`updated_at` as `b_updated_at`, `b`.`title` as `b_title`, `b`.`author_id` as `b_author_id`, `b`.`publisher_id` as `b_publisher_id`, `b`.`meta` as `b_meta`, ' + - '`t`.`id` as `t_id`, `t`.`created_at` as `t_created_at`, `t`.`updated_at` as `t_updated_at`, `t`.`name` as `t_name`, `t`.`version` as `t_version` ' + + '`b`.`id` as `b__id`, `b`.`created_at` as `b__created_at`, `b`.`updated_at` as `b__updated_at`, `b`.`title` as `b__title`, `b`.`author_id` as `b__author_id`, `b`.`publisher_id` as `b__publisher_id`, `b`.`meta` as `b__meta`, ' + + '`t`.`id` as `t__id`, `t`.`created_at` as `t__created_at`, `t`.`updated_at` as `t__updated_at`, `t`.`name` as `t__name`, `t`.`version` as `t__version` ' + 'from `author4` as `a` ' + 'left join `book4` as `b` on `a`.`id` = `b`.`author_id` ' + 'left join `tags_ordered` as `e1` on `b`.`id` = `e1`.`book4_id` ' + diff --git a/tests/QueryBuilder.test.ts b/tests/QueryBuilder.test.ts index 0fe1938bd0cf..d99a0f06ab09 100644 --- a/tests/QueryBuilder.test.ts +++ b/tests/QueryBuilder.test.ts @@ -204,8 +204,8 @@ describe('QueryBuilder', () => { .where({ 'fz.name': 'baz' }) .limit(1); const sql = 'select `fb1`.*, ' + - '`fz`.`id` as `fz_id`, `fz`.`name` as `fz_name`, `fz`.`version` as `fz_version`, ' + - '`fb2`.`id` as `fb2_id`, `fb2`.`name` as `fb2_name`, `fb2`.`baz_id` as `fb2_baz_id`, `fb2`.`foo_bar_id` as `fb2_foo_bar_id`, `fb2`.`version` as `fb2_version`, `fb2`.`blob` as `fb2_blob`, `fb2`.`array` as `fb2_array`, `fb2`.`object` as `fb2_object`, (select 123) as `fb2_random`, ' + + '`fz`.`id` as `fz__id`, `fz`.`name` as `fz__name`, `fz`.`version` as `fz__version`, ' + + '`fb2`.`id` as `fb2__id`, `fb2`.`name` as `fb2__name`, `fb2`.`baz_id` as `fb2__baz_id`, `fb2`.`foo_bar_id` as `fb2__foo_bar_id`, `fb2`.`version` as `fb2__version`, `fb2`.`blob` as `fb2__blob`, `fb2`.`array` as `fb2__array`, `fb2`.`object` as `fb2__object`, (select 123) as `fb2__random`, ' + '(select 123) as `random` from `foo_bar2` as `fb1` ' + 'inner join `foo_baz2` as `fz` on `fb1`.`baz_id` = `fz`.`id` ' + 'left join `foo_bar2` as `fb2` on `fz`.`id` = `fb2`.`baz_id` ' + diff --git a/tests/issues/GH1041.test.ts b/tests/issues/GH1041.test.ts index 693324230c9e..d25c1f1ac217 100644 --- a/tests/issues/GH1041.test.ts +++ b/tests/issues/GH1041.test.ts @@ -97,7 +97,7 @@ describe('GH issue 1041, 1043', () => { test('joined strategy: find by many-to-many relation ID', async () => { const findPromise = orm.em.findOne(User, { apps: 1 }, { populate: { apps: LoadStrategy.JOINED } }); await expect(findPromise).resolves.toBeInstanceOf(User); - expect(log.mock.calls[0][0]).toMatch('select `e0`.`id`, `e0`.`name`, `a1`.`id` as `a1_id`, `a1`.`name` as `a1_name` from `user` as `e0` left join `user_apps` as `e2` on `e0`.`id` = `e2`.`user_id` left join `app` as `a1` on `e2`.`app_id` = `a1`.`id` where `e2`.`app_id` = 1'); + expect(log.mock.calls[0][0]).toMatch('select `e0`.`id`, `e0`.`name`, `a1`.`id` as `a1__id`, `a1`.`name` as `a1__name` from `user` as `e0` left join `user_apps` as `e2` on `e0`.`id` = `e2`.`user_id` left join `app` as `a1` on `e2`.`app_id` = `a1`.`id` where `e2`.`app_id` = 1'); }); test('select-in strategy: find by many-to-many relation IDs', async () => { @@ -110,7 +110,7 @@ describe('GH issue 1041, 1043', () => { test('joined strategy: find by many-to-many relation IDs', async () => { const findPromise = orm.em.findOne(User, { apps: [1, 2, 3] }, { populate: { apps: LoadStrategy.JOINED } }); await expect(findPromise).resolves.toBeInstanceOf(User); - expect(log.mock.calls[0][0]).toMatch('select `e0`.`id`, `e0`.`name`, `a1`.`id` as `a1_id`, `a1`.`name` as `a1_name` from `user` as `e0` left join `user_apps` as `e2` on `e0`.`id` = `e2`.`user_id` left join `app` as `a1` on `e2`.`app_id` = `a1`.`id` where `e2`.`app_id` in (1, 2, 3)'); + expect(log.mock.calls[0][0]).toMatch('select `e0`.`id`, `e0`.`name`, `a1`.`id` as `a1__id`, `a1`.`name` as `a1__name` from `user` as `e0` left join `user_apps` as `e2` on `e0`.`id` = `e2`.`user_id` left join `app` as `a1` on `e2`.`app_id` = `a1`.`id` where `e2`.`app_id` in (1, 2, 3)'); }); }); diff --git a/tests/issues/GH1171.test.ts b/tests/issues/GH1171.test.ts index fc9d5d48ae54..b424b83497cd 100644 --- a/tests/issues/GH1171.test.ts +++ b/tests/issues/GH1171.test.ts @@ -50,11 +50,12 @@ describe('GH issue 1171', () => { const orderedAs = await orm.em .createQueryBuilder(A) .select('*') - .leftJoinAndSelect('b', 'b0') - .orderBy({ 'b0.name': 'asc' }) + .leftJoinAndSelect('b', 'b') + .orderBy({ 'b.name': 'asc' }) .getResult(); expect(orderedAs.map(e => e.id)).toEqual([a3.id, a2.id, a1.id]); + expect(orderedAs.map(e => e.b.name)).toEqual([b3.name, b2.name, b1.name]); }); }); diff --git a/tests/joined-strategy.postgre.test.ts b/tests/joined-strategy.postgre.test.ts index 2a67589ad198..145203a8f624 100644 --- a/tests/joined-strategy.postgre.test.ts +++ b/tests/joined-strategy.postgre.test.ts @@ -105,7 +105,7 @@ describe('Joined loading strategy', () => { await orm.em.findOneOrFail(Author2, { id: author2.id }, { populate: { books2: { perex: true } } }); expect(mock.mock.calls.length).toBe(1); expect(mock.mock.calls[0][0]).toMatch('select "e0"."id", "e0"."created_at", "e0"."updated_at", "e0"."name", "e0"."email", "e0"."age", "e0"."terms_accepted", "e0"."optional", "e0"."identities", "e0"."born", "e0"."born_time", "e0"."favourite_book_uuid_pk", "e0"."favourite_author_id", ' + - '"b1"."uuid_pk" as "b1_uuid_pk", "b1"."created_at" as "b1_created_at", "b1"."title" as "b1_title", "b1"."perex" as "b1_perex", "b1"."price" as "b1_price", "b1".price * 1.19 as "b1_price_taxed", "b1"."double" as "b1_double", "b1"."meta" as "b1_meta", "b1"."author_id" as "b1_author_id", "b1"."publisher_id" as "b1_publisher_id" ' + + '"b1"."uuid_pk" as "b1__uuid_pk", "b1"."created_at" as "b1__created_at", "b1"."title" as "b1__title", "b1"."perex" as "b1__perex", "b1"."price" as "b1__price", "b1".price * 1.19 as "b1__price_taxed", "b1"."double" as "b1__double", "b1"."meta" as "b1__meta", "b1"."author_id" as "b1__author_id", "b1"."publisher_id" as "b1__publisher_id" ' + 'from "author2" as "e0" ' + 'left join "book2" as "b1" on "e0"."id" = "b1"."author_id" ' + 'where "e0"."id" = $1'); @@ -115,7 +115,7 @@ describe('Joined loading strategy', () => { await orm.em.findOneOrFail(Author2, { id: author2.id }, { populate: { books2: true } }); expect(mock.mock.calls.length).toBe(1); expect(mock.mock.calls[0][0]).toMatch('select "e0"."id", "e0"."created_at", "e0"."updated_at", "e0"."name", "e0"."email", "e0"."age", "e0"."terms_accepted", "e0"."optional", "e0"."identities", "e0"."born", "e0"."born_time", "e0"."favourite_book_uuid_pk", "e0"."favourite_author_id", ' + - '"b1"."uuid_pk" as "b1_uuid_pk", "b1"."created_at" as "b1_created_at", "b1"."title" as "b1_title", "b1"."price" as "b1_price", "b1".price * 1.19 as "b1_price_taxed", "b1"."double" as "b1_double", "b1"."meta" as "b1_meta", "b1"."author_id" as "b1_author_id", "b1"."publisher_id" as "b1_publisher_id" ' + + '"b1"."uuid_pk" as "b1__uuid_pk", "b1"."created_at" as "b1__created_at", "b1"."title" as "b1__title", "b1"."price" as "b1__price", "b1".price * 1.19 as "b1__price_taxed", "b1"."double" as "b1__double", "b1"."meta" as "b1__meta", "b1"."author_id" as "b1__author_id", "b1"."publisher_id" as "b1__publisher_id" ' + 'from "author2" as "e0" ' + 'left join "book2" as "b1" on "e0"."id" = "b1"."author_id" ' + 'where "e0"."id" = $1'); @@ -125,7 +125,7 @@ describe('Joined loading strategy', () => { await orm.em.findOneOrFail(Author2, { id: author2.id }, { populate: { books: true } }); expect(mock.mock.calls.length).toBe(1); expect(mock.mock.calls[0][0]).toMatch('select "e0"."id", "e0"."created_at", "e0"."updated_at", "e0"."name", "e0"."email", "e0"."age", "e0"."terms_accepted", "e0"."optional", "e0"."identities", "e0"."born", "e0"."born_time", "e0"."favourite_book_uuid_pk", "e0"."favourite_author_id", ' + - '"b1"."uuid_pk" as "b1_uuid_pk", "b1"."created_at" as "b1_created_at", "b1"."title" as "b1_title", "b1"."price" as "b1_price", "b1".price * 1.19 as "b1_price_taxed", "b1"."double" as "b1_double", "b1"."meta" as "b1_meta", "b1"."author_id" as "b1_author_id", "b1"."publisher_id" as "b1_publisher_id" ' + + '"b1"."uuid_pk" as "b1__uuid_pk", "b1"."created_at" as "b1__created_at", "b1"."title" as "b1__title", "b1"."price" as "b1__price", "b1".price * 1.19 as "b1__price_taxed", "b1"."double" as "b1__double", "b1"."meta" as "b1__meta", "b1"."author_id" as "b1__author_id", "b1"."publisher_id" as "b1__publisher_id" ' + 'from "author2" as "e0" ' + 'left join "book2" as "b1" on "e0"."id" = "b1"."author_id" ' + 'where "e0"."id" = $1'); @@ -135,7 +135,7 @@ describe('Joined loading strategy', () => { await orm.em.findOneOrFail(Author2, { id: author2.id }, { populate: { books: { perex: true } } }); expect(mock.mock.calls.length).toBe(1); expect(mock.mock.calls[0][0]).toMatch('select "e0"."id", "e0"."created_at", "e0"."updated_at", "e0"."name", "e0"."email", "e0"."age", "e0"."terms_accepted", "e0"."optional", "e0"."identities", "e0"."born", "e0"."born_time", "e0"."favourite_book_uuid_pk", "e0"."favourite_author_id", ' + - '"b1"."uuid_pk" as "b1_uuid_pk", "b1"."created_at" as "b1_created_at", "b1"."title" as "b1_title", "b1"."perex" as "b1_perex", "b1"."price" as "b1_price", "b1".price * 1.19 as "b1_price_taxed", "b1"."double" as "b1_double", "b1"."meta" as "b1_meta", "b1"."author_id" as "b1_author_id", "b1"."publisher_id" as "b1_publisher_id" ' + + '"b1"."uuid_pk" as "b1__uuid_pk", "b1"."created_at" as "b1__created_at", "b1"."title" as "b1__title", "b1"."perex" as "b1__perex", "b1"."price" as "b1__price", "b1".price * 1.19 as "b1__price_taxed", "b1"."double" as "b1__double", "b1"."meta" as "b1__meta", "b1"."author_id" as "b1__author_id", "b1"."publisher_id" as "b1__publisher_id" ' + 'from "author2" as "e0" ' + 'left join "book2" as "b1" on "e0"."id" = "b1"."author_id" ' + 'where "e0"."id" = $1'); @@ -156,7 +156,7 @@ describe('Joined loading strategy', () => { await orm.em.find(Author2, { id: author2.id }, { populate: { books2: { perex: true } } }); expect(mock.mock.calls.length).toBe(1); expect(mock.mock.calls[0][0]).toMatch('select "e0"."id", "e0"."created_at", "e0"."updated_at", "e0"."name", "e0"."email", "e0"."age", "e0"."terms_accepted", "e0"."optional", "e0"."identities", "e0"."born", "e0"."born_time", "e0"."favourite_book_uuid_pk", "e0"."favourite_author_id", ' + - '"b1"."uuid_pk" as "b1_uuid_pk", "b1"."created_at" as "b1_created_at", "b1"."title" as "b1_title", "b1"."perex" as "b1_perex", "b1"."price" as "b1_price", "b1".price * 1.19 as "b1_price_taxed", "b1"."double" as "b1_double", "b1"."meta" as "b1_meta", "b1"."author_id" as "b1_author_id", "b1"."publisher_id" as "b1_publisher_id" ' + + '"b1"."uuid_pk" as "b1__uuid_pk", "b1"."created_at" as "b1__created_at", "b1"."title" as "b1__title", "b1"."perex" as "b1__perex", "b1"."price" as "b1__price", "b1".price * 1.19 as "b1__price_taxed", "b1"."double" as "b1__double", "b1"."meta" as "b1__meta", "b1"."author_id" as "b1__author_id", "b1"."publisher_id" as "b1__publisher_id" ' + 'from "author2" as "e0" ' + 'left join "book2" as "b1" on "e0"."id" = "b1"."author_id" ' + 'where "e0"."id" = $1'); @@ -166,7 +166,7 @@ describe('Joined loading strategy', () => { await orm.em.find(Author2, { id: author2.id }, { populate: { books2: true } }); expect(mock.mock.calls.length).toBe(1); expect(mock.mock.calls[0][0]).toMatch('select "e0"."id", "e0"."created_at", "e0"."updated_at", "e0"."name", "e0"."email", "e0"."age", "e0"."terms_accepted", "e0"."optional", "e0"."identities", "e0"."born", "e0"."born_time", "e0"."favourite_book_uuid_pk", "e0"."favourite_author_id", ' + - '"b1"."uuid_pk" as "b1_uuid_pk", "b1"."created_at" as "b1_created_at", "b1"."title" as "b1_title", "b1"."price" as "b1_price", "b1".price * 1.19 as "b1_price_taxed", "b1"."double" as "b1_double", "b1"."meta" as "b1_meta", "b1"."author_id" as "b1_author_id", "b1"."publisher_id" as "b1_publisher_id" ' + + '"b1"."uuid_pk" as "b1__uuid_pk", "b1"."created_at" as "b1__created_at", "b1"."title" as "b1__title", "b1"."price" as "b1__price", "b1".price * 1.19 as "b1__price_taxed", "b1"."double" as "b1__double", "b1"."meta" as "b1__meta", "b1"."author_id" as "b1__author_id", "b1"."publisher_id" as "b1__publisher_id" ' + 'from "author2" as "e0" ' + 'left join "book2" as "b1" on "e0"."id" = "b1"."author_id" ' + 'where "e0"."id" = $1'); @@ -176,7 +176,7 @@ describe('Joined loading strategy', () => { await orm.em.find(Author2, { id: author2.id }, { populate: { books: LoadStrategy.JOINED } }); expect(mock.mock.calls.length).toBe(1); expect(mock.mock.calls[0][0]).toMatch('select "e0"."id", "e0"."created_at", "e0"."updated_at", "e0"."name", "e0"."email", "e0"."age", "e0"."terms_accepted", "e0"."optional", "e0"."identities", "e0"."born", "e0"."born_time", "e0"."favourite_book_uuid_pk", "e0"."favourite_author_id", ' + - '"b1"."uuid_pk" as "b1_uuid_pk", "b1"."created_at" as "b1_created_at", "b1"."title" as "b1_title", "b1"."price" as "b1_price", "b1".price * 1.19 as "b1_price_taxed", "b1"."double" as "b1_double", "b1"."meta" as "b1_meta", "b1"."author_id" as "b1_author_id", "b1"."publisher_id" as "b1_publisher_id" ' + + '"b1"."uuid_pk" as "b1__uuid_pk", "b1"."created_at" as "b1__created_at", "b1"."title" as "b1__title", "b1"."price" as "b1__price", "b1".price * 1.19 as "b1__price_taxed", "b1"."double" as "b1__double", "b1"."meta" as "b1__meta", "b1"."author_id" as "b1__author_id", "b1"."publisher_id" as "b1__publisher_id" ' + 'from "author2" as "e0" ' + 'left join "book2" as "b1" on "e0"."id" = "b1"."author_id" ' + 'where "e0"."id" = $1'); @@ -186,7 +186,7 @@ describe('Joined loading strategy', () => { await orm.em.find(Author2, { id: author2.id }, { populate: { books: { perex: true } } }); expect(mock.mock.calls.length).toBe(1); expect(mock.mock.calls[0][0]).toMatch('select "e0"."id", "e0"."created_at", "e0"."updated_at", "e0"."name", "e0"."email", "e0"."age", "e0"."terms_accepted", "e0"."optional", "e0"."identities", "e0"."born", "e0"."born_time", "e0"."favourite_book_uuid_pk", "e0"."favourite_author_id", ' + - '"b1"."uuid_pk" as "b1_uuid_pk", "b1"."created_at" as "b1_created_at", "b1"."title" as "b1_title", "b1"."perex" as "b1_perex", "b1"."price" as "b1_price", "b1".price * 1.19 as "b1_price_taxed", "b1"."double" as "b1_double", "b1"."meta" as "b1_meta", "b1"."author_id" as "b1_author_id", "b1"."publisher_id" as "b1_publisher_id" ' + + '"b1"."uuid_pk" as "b1__uuid_pk", "b1"."created_at" as "b1__created_at", "b1"."title" as "b1__title", "b1"."perex" as "b1__perex", "b1"."price" as "b1__price", "b1".price * 1.19 as "b1__price_taxed", "b1"."double" as "b1__double", "b1"."meta" as "b1__meta", "b1"."author_id" as "b1__author_id", "b1"."publisher_id" as "b1__publisher_id" ' + 'from "author2" as "e0" ' + 'left join "book2" as "b1" on "e0"."id" = "b1"."author_id" ' + 'where "e0"."id" = $1'); @@ -221,7 +221,7 @@ describe('Joined loading strategy', () => { const books = await orm.em.find(Book2, {}, { populate: { tags: LoadStrategy.JOINED }, orderBy: { tags: { name: 'desc' } } }); expect(mock.mock.calls.length).toBe(1); expect(mock.mock.calls[0][0]).toMatch('select "e0"."uuid_pk", "e0"."created_at", "e0"."title", "e0"."price", "e0".price * 1.19 as "price_taxed", "e0"."double", "e0"."meta", "e0"."author_id", "e0"."publisher_id", ' + - '"t1"."id" as "t1_id", "t1"."name" as "t1_name", "e0".price * 1.19 as "price_taxed" ' + + '"t1"."id" as "t1__id", "t1"."name" as "t1__name", "e0".price * 1.19 as "price_taxed" ' + 'from "book2" as "e0" ' + 'left join "book2_tags" as "e2" on "e0"."uuid_pk" = "e2"."book2_uuid_pk" ' + 'left join "book_tag2" as "t1" on "e2"."book_tag2_id" = "t1"."id" ' + @@ -313,7 +313,7 @@ describe('Joined loading strategy', () => { const b1 = (await orm.em.findOne(FooBaz2, { id: baz.id }, { populate: ['bar'], strategy: LoadStrategy.JOINED }))!; expect(mock.mock.calls).toHaveLength(2); expect(mock.mock.calls[1][0]).toMatch('select "e0"."id", "e0"."name", "e0"."version", ' + - '"b1"."id" as "b1_id", "b1"."name" as "b1_name", "b1"."baz_id" as "b1_baz_id", "b1"."foo_bar_id" as "b1_foo_bar_id", "b1"."version" as "b1_version", "b1"."blob" as "b1_blob", "b1"."array" as "b1_array", "b1"."object" as "b1_object", (select 123) as "b1_random", "b1"."id" as "bar_id" ' + + '"b1"."id" as "b1__id", "b1"."name" as "b1__name", "b1"."baz_id" as "b1__baz_id", "b1"."foo_bar_id" as "b1__foo_bar_id", "b1"."version" as "b1__version", "b1"."blob" as "b1__blob", "b1"."array" as "b1__array", "b1"."object" as "b1__object", (select 123) as "b1__random", "b1"."id" as "bar_id" ' + 'from "foo_baz2" as "e0" ' + 'left join "foo_bar2" as "b1" on "e0"."id" = "b1"."baz_id" ' + 'where "e0"."id" = $1'); @@ -326,7 +326,7 @@ describe('Joined loading strategy', () => { const b2 = (await orm.em.findOne(FooBaz2, { bar: bar.id }, { populate: { bar: true } }))!; expect(mock.mock.calls).toHaveLength(3); expect(mock.mock.calls[2][0]).toMatch('select "e0"."id", "e0"."name", "e0"."version", ' + - '"b1"."id" as "b1_id", "b1"."name" as "b1_name", "b1"."baz_id" as "b1_baz_id", "b1"."foo_bar_id" as "b1_foo_bar_id", "b1"."version" as "b1_version", "b1"."blob" as "b1_blob", "b1"."array" as "b1_array", "b1"."object" as "b1_object", (select 123) as "b1_random", "b1"."id" as "bar_id" ' + + '"b1"."id" as "b1__id", "b1"."name" as "b1__name", "b1"."baz_id" as "b1__baz_id", "b1"."foo_bar_id" as "b1__foo_bar_id", "b1"."version" as "b1__version", "b1"."blob" as "b1__blob", "b1"."array" as "b1__array", "b1"."object" as "b1__object", (select 123) as "b1__random", "b1"."id" as "bar_id" ' + 'from "foo_baz2" as "e0" ' + 'left join "foo_bar2" as "b1" on "e0"."id" = "b1"."baz_id" ' + 'where "b1"."id" = $1'); @@ -375,10 +375,10 @@ describe('Joined loading strategy', () => { }); expect(mock.mock.calls.length).toBe(1); expect(mock.mock.calls[0][0]).toMatch('select "e0"."id", "e0"."name", ' + - '"b1"."uuid_pk" as "b1_uuid_pk", "b1"."created_at" as "b1_created_at", "b1"."title" as "b1_title", "b1"."price" as "b1_price", "b1".price * 1.19 as "b1_price_taxed", "b1"."double" as "b1_double", "b1"."meta" as "b1_meta", "b1"."author_id" as "b1_author_id", "b1"."publisher_id" as "b1_publisher_id", ' + - '"a3"."id" as "a3_id", "a3"."created_at" as "a3_created_at", "a3"."updated_at" as "a3_updated_at", "a3"."name" as "a3_name", "a3"."email" as "a3_email", "a3"."age" as "a3_age", "a3"."terms_accepted" as "a3_terms_accepted", "a3"."optional" as "a3_optional", "a3"."identities" as "a3_identities", "a3"."born" as "a3_born", "a3"."born_time" as "a3_born_time", "a3"."favourite_book_uuid_pk" as "a3_favourite_book_uuid_pk", "a3"."favourite_author_id" as "a3_favourite_author_id", ' + - '"p4"."id" as "p4_id", "p4"."name" as "p4_name", "p4"."type" as "p4_type", "p4"."type2" as "p4_type2", "p4"."enum1" as "p4_enum1", "p4"."enum2" as "p4_enum2", "p4"."enum3" as "p4_enum3", "p4"."enum4" as "p4_enum4", ' + - '"t5"."id" as "t5_id", "t5"."name" as "t5_name", "t5"."book_uuid_pk" as "t5_book_uuid_pk", "t5"."parent_id" as "t5_parent_id", "t5"."version" as "t5_version" ' + + '"b1"."uuid_pk" as "b1__uuid_pk", "b1"."created_at" as "b1__created_at", "b1"."title" as "b1__title", "b1"."price" as "b1__price", "b1".price * 1.19 as "b1__price_taxed", "b1"."double" as "b1__double", "b1"."meta" as "b1__meta", "b1"."author_id" as "b1__author_id", "b1"."publisher_id" as "b1__publisher_id", ' + + '"a3"."id" as "a3__id", "a3"."created_at" as "a3__created_at", "a3"."updated_at" as "a3__updated_at", "a3"."name" as "a3__name", "a3"."email" as "a3__email", "a3"."age" as "a3__age", "a3"."terms_accepted" as "a3__terms_accepted", "a3"."optional" as "a3__optional", "a3"."identities" as "a3__identities", "a3"."born" as "a3__born", "a3"."born_time" as "a3__born_time", "a3"."favourite_book_uuid_pk" as "a3__favourite_book_uuid_pk", "a3"."favourite_author_id" as "a3__favourite_author_id", ' + + '"p4"."id" as "p4__id", "p4"."name" as "p4__name", "p4"."type" as "p4__type", "p4"."type2" as "p4__type2", "p4"."enum1" as "p4__enum1", "p4"."enum2" as "p4__enum2", "p4"."enum3" as "p4__enum3", "p4"."enum4" as "p4__enum4", ' + + '"t5"."id" as "t5__id", "t5"."name" as "t5__name", "t5"."book_uuid_pk" as "t5__book_uuid_pk", "t5"."parent_id" as "t5__parent_id", "t5"."version" as "t5__version" ' + 'from "book_tag2" as "e0" ' + 'left join "book2_tags" as "e2" on "e0"."id" = "e2"."book_tag2_id" ' + 'left join "book2" as "b1" on "e2"."book2_uuid_pk" = "b1"."uuid_pk" ' + @@ -446,7 +446,7 @@ describe('Joined loading strategy', () => { expect(res1[0].test).toBeUndefined(); expect(mock.mock.calls.length).toBe(1); expect(mock.mock.calls[0][0]).toMatch('select "e0"."uuid_pk", "e0"."created_at", "e0"."title", "e0"."perex", "e0"."price", "e0".price * 1.19 as "price_taxed", "e0"."double", "e0"."meta", "e0"."author_id", "e0"."publisher_id", ' + - '"a1"."id" as "a1_id", "a1"."created_at" as "a1_created_at", "a1"."updated_at" as "a1_updated_at", "a1"."name" as "a1_name", "a1"."email" as "a1_email", "a1"."age" as "a1_age", "a1"."terms_accepted" as "a1_terms_accepted", "a1"."optional" as "a1_optional", "a1"."identities" as "a1_identities", "a1"."born" as "a1_born", "a1"."born_time" as "a1_born_time", "a1"."favourite_book_uuid_pk" as "a1_favourite_book_uuid_pk", "a1"."favourite_author_id" as "a1_favourite_author_id", "e0".price * 1.19 as "price_taxed" ' + + '"a1"."id" as "a1__id", "a1"."created_at" as "a1__created_at", "a1"."updated_at" as "a1__updated_at", "a1"."name" as "a1__name", "a1"."email" as "a1__email", "a1"."age" as "a1__age", "a1"."terms_accepted" as "a1__terms_accepted", "a1"."optional" as "a1__optional", "a1"."identities" as "a1__identities", "a1"."born" as "a1__born", "a1"."born_time" as "a1__born_time", "a1"."favourite_book_uuid_pk" as "a1__favourite_book_uuid_pk", "a1"."favourite_author_id" as "a1__favourite_author_id", "e0".price * 1.19 as "price_taxed" ' + 'from "book2" as "e0" ' + 'left join "author2" as "a1" on "e0"."author_id" = "a1"."id" ' + 'where "e0"."author_id" is not null and "a1"."name" = $1'); @@ -457,9 +457,9 @@ describe('Joined loading strategy', () => { expect(res2).toHaveLength(3); expect(mock.mock.calls.length).toBe(1); expect(mock.mock.calls[0][0]).toMatch('select "e0"."uuid_pk", "e0"."created_at", "e0"."title", "e0"."perex", "e0"."price", "e0".price * 1.19 as "price_taxed", "e0"."double", "e0"."meta", "e0"."author_id", "e0"."publisher_id", ' + - '"a1"."id" as "a1_id", "a1"."created_at" as "a1_created_at", "a1"."updated_at" as "a1_updated_at", "a1"."name" as "a1_name", "a1"."email" as "a1_email", "a1"."age" as "a1_age", "a1"."terms_accepted" as "a1_terms_accepted", "a1"."optional" as "a1_optional", "a1"."identities" as "a1_identities", "a1"."born" as "a1_born", "a1"."born_time" as "a1_born_time", "a1"."favourite_book_uuid_pk" as "a1_favourite_book_uuid_pk", "a1"."favourite_author_id" as "a1_favourite_author_id", ' + - '"f2"."uuid_pk" as "f2_uuid_pk", "f2"."created_at" as "f2_created_at", "f2"."title" as "f2_title", "f2"."price" as "f2_price", "f2".price * 1.19 as "f2_price_taxed", "f2"."double" as "f2_double", "f2"."meta" as "f2_meta", "f2"."author_id" as "f2_author_id", "f2"."publisher_id" as "f2_publisher_id", ' + - '"a3"."id" as "a3_id", "a3"."created_at" as "a3_created_at", "a3"."updated_at" as "a3_updated_at", "a3"."name" as "a3_name", "a3"."email" as "a3_email", "a3"."age" as "a3_age", "a3"."terms_accepted" as "a3_terms_accepted", "a3"."optional" as "a3_optional", "a3"."identities" as "a3_identities", "a3"."born" as "a3_born", "a3"."born_time" as "a3_born_time", "a3"."favourite_book_uuid_pk" as "a3_favourite_book_uuid_pk", "a3"."favourite_author_id" as "a3_favourite_author_id", "e0".price * 1.19 as "price_taxed" ' + + '"a1"."id" as "a1__id", "a1"."created_at" as "a1__created_at", "a1"."updated_at" as "a1__updated_at", "a1"."name" as "a1__name", "a1"."email" as "a1__email", "a1"."age" as "a1__age", "a1"."terms_accepted" as "a1__terms_accepted", "a1"."optional" as "a1__optional", "a1"."identities" as "a1__identities", "a1"."born" as "a1__born", "a1"."born_time" as "a1__born_time", "a1"."favourite_book_uuid_pk" as "a1__favourite_book_uuid_pk", "a1"."favourite_author_id" as "a1__favourite_author_id", ' + + '"f2"."uuid_pk" as "f2__uuid_pk", "f2"."created_at" as "f2__created_at", "f2"."title" as "f2__title", "f2"."price" as "f2__price", "f2".price * 1.19 as "f2__price_taxed", "f2"."double" as "f2__double", "f2"."meta" as "f2__meta", "f2"."author_id" as "f2__author_id", "f2"."publisher_id" as "f2__publisher_id", ' + + '"a3"."id" as "a3__id", "a3"."created_at" as "a3__created_at", "a3"."updated_at" as "a3__updated_at", "a3"."name" as "a3__name", "a3"."email" as "a3__email", "a3"."age" as "a3__age", "a3"."terms_accepted" as "a3__terms_accepted", "a3"."optional" as "a3__optional", "a3"."identities" as "a3__identities", "a3"."born" as "a3__born", "a3"."born_time" as "a3__born_time", "a3"."favourite_book_uuid_pk" as "a3__favourite_book_uuid_pk", "a3"."favourite_author_id" as "a3__favourite_author_id", "e0".price * 1.19 as "price_taxed" ' + 'from "book2" as "e0" ' + 'left join "author2" as "a1" on "e0"."author_id" = "a1"."id" ' + 'left join "book2" as "f2" on "a1"."favourite_book_uuid_pk" = "f2"."uuid_pk" ' + @@ -482,7 +482,7 @@ describe('Joined loading strategy', () => { expect(res4).toHaveLength(3); expect(mock.mock.calls.length).toBe(1); expect(mock.mock.calls[0][0]).toMatch('select "e0"."uuid_pk", "e0"."created_at", "e0"."title", "e0"."perex", "e0"."price", "e0".price * 1.19 as "price_taxed", "e0"."double", "e0"."meta", "e0"."author_id", "e0"."publisher_id", ' + - '"a1"."id" as "a1_id", "a1"."created_at" as "a1_created_at", "a1"."updated_at" as "a1_updated_at", "a1"."name" as "a1_name", "a1"."email" as "a1_email", "a1"."age" as "a1_age", "a1"."terms_accepted" as "a1_terms_accepted", "a1"."optional" as "a1_optional", "a1"."identities" as "a1_identities", "a1"."born" as "a1_born", "a1"."born_time" as "a1_born_time", "a1"."favourite_book_uuid_pk" as "a1_favourite_book_uuid_pk", "a1"."favourite_author_id" as "a1_favourite_author_id", "e0".price * 1.19 as "price_taxed" ' + + '"a1"."id" as "a1__id", "a1"."created_at" as "a1__created_at", "a1"."updated_at" as "a1__updated_at", "a1"."name" as "a1__name", "a1"."email" as "a1__email", "a1"."age" as "a1__age", "a1"."terms_accepted" as "a1__terms_accepted", "a1"."optional" as "a1__optional", "a1"."identities" as "a1__identities", "a1"."born" as "a1__born", "a1"."born_time" as "a1__born_time", "a1"."favourite_book_uuid_pk" as "a1__favourite_book_uuid_pk", "a1"."favourite_author_id" as "a1__favourite_author_id", "e0".price * 1.19 as "price_taxed" ' + 'from "book2" as "e0" ' + 'left join "author2" as "a1" on "e0"."author_id" = "a1"."id" ' + 'left join "book2" as "e2" on "a1"."favourite_book_uuid_pk" = "e2"."uuid_pk" ' +