Skip to content

Commit

Permalink
fix(core): fix ordering by pivot table with explicit schema name
Browse files Browse the repository at this point in the history
Closes #2621
  • Loading branch information
B4nan committed Jan 15, 2022
1 parent 7c3de26 commit eb1f9bb
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/metadata/MetadataDiscovery.ts
Expand Up @@ -80,7 +80,7 @@ export class MetadataDiscovery {
filtered.forEach(meta => this.autoWireBidirectionalProperties(meta));

for (const meta of filtered) {
discovered.push(...(await this.processEntity(meta)));
discovered.push(...await this.processEntity(meta));
}

discovered.forEach(meta => meta.sync(true));
Expand Down
8 changes: 3 additions & 5 deletions packages/knex/src/query/QueryBuilderHelper.ts
Expand Up @@ -489,8 +489,6 @@ export class QueryBuilderHelper {
const column = this.mapper(noPrefix ? f : `${alias}.${f}`, type);
/* istanbul ignore next */
const rawColumn = Utils.isString(column) ? column.split('.').map(e => this.knex.ref(e)).join('.') : column;


const customOrder = prop?.customOrder;

const colPart = customOrder
Expand All @@ -514,9 +512,9 @@ export class QueryBuilderHelper {
}

splitField(field: string): [string, string] {
const [a, b] = field.split('.');
const fromAlias = b ? a : this.alias;
const fromField = b || a;
const parts = field.split('.');
const fromField = parts.pop()!;
const fromAlias = parts.length > 0 ? parts.join('.') : this.alias;

return [fromAlias, fromField];
}
Expand Down
6 changes: 3 additions & 3 deletions tests/EntityManager.postgre.test.ts
Expand Up @@ -129,9 +129,9 @@ describe('EntityManagerPostgre', () => {
]);

expect(mock.mock.calls[0][0]).toMatch('insert into "publisher2" ("name", "type", "type2") values ($1, $2, $3), ($4, $5, $6), ($7, $8, $9) returning "id"');
expect(mock.mock.calls[1][0]).toMatch('insert into "publisher2_tests" ("publisher2_id", "test2_id") values ($1, $2), ($3, $4), ($5, $6)');
expect(mock.mock.calls[2][0]).toMatch('insert into "publisher2_tests" ("publisher2_id", "test2_id") values ($1, $2), ($3, $4)');
expect(mock.mock.calls[3][0]).toMatch('insert into "publisher2_tests" ("publisher2_id", "test2_id") values ($1, $2), ($3, $4), ($5, $6)');
expect(mock.mock.calls[1][0]).toMatch('insert into "public"."publisher2_tests" ("publisher2_id", "test2_id") values ($1, $2), ($3, $4), ($5, $6)');
expect(mock.mock.calls[2][0]).toMatch('insert into "public"."publisher2_tests" ("publisher2_id", "test2_id") values ($1, $2), ($3, $4)');
expect(mock.mock.calls[3][0]).toMatch('insert into "public"."publisher2_tests" ("publisher2_id", "test2_id") values ($1, $2), ($3, $4), ($5, $6)');

// postgres returns all the ids based on returning clause
expect(res).toMatchObject({ insertId: 1, affectedRows: 3, row: { id: 1 }, rows: [ { id: 1 }, { id: 2 }, { id: 3 } ] });
Expand Down
2 changes: 1 addition & 1 deletion tests/entities-sql/Publisher2.ts
Expand Up @@ -32,7 +32,7 @@ export class Publisher2 extends BaseEntity2 {
@OneToMany(() => Book2, 'publisher', { joinColumn: 'book_uuid', inverseJoinColumn: 'publisher_id' })
books!: Collection<Book2>;

@ManyToMany({ entity: () => Test2, fixedOrder: true })
@ManyToMany({ entity: () => Test2, pivotTable: 'public.publisher2_tests', fixedOrder: true })
tests!: Collection<Test2>;

@Enum(() => PublisherType)
Expand Down

0 comments on commit eb1f9bb

Please sign in to comment.