Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Revert "fix: ordering by joined columns for PostgreSQL (#3736) (#8118)" This reverts commit 1649882. * test: add a test for leftJoinAndSelect with ordering by a relation property and a limit (#8346)
- Loading branch information
Showing
7 changed files
with
92 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { | ||
BaseEntity, | ||
Column, | ||
Entity, | ||
OneToMany, | ||
PrimaryGeneratedColumn, | ||
} from "../../../../src"; | ||
|
||
import { CustomerContact } from './CustomerContact'; | ||
|
||
@Entity('Customer') | ||
export class Customer extends BaseEntity { | ||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column() | ||
name: string; | ||
|
||
@OneToMany(() => CustomerContact, (contact) => contact.customer) | ||
contacts: CustomerContact[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { | ||
Column, | ||
Entity, | ||
Index, | ||
ManyToOne, | ||
PrimaryGeneratedColumn, | ||
} from "../../../../src"; | ||
|
||
import { Customer } from './Customer'; | ||
|
||
@Entity('CustomerContact') | ||
@Index(['firstName', 'lastName']) | ||
export class CustomerContact { | ||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@ManyToOne(() => Customer, (customer) => customer.contacts) | ||
customer: Customer; | ||
|
||
@Column({ default: '' }) | ||
firstName: string; | ||
|
||
@Column({ default: '' }) | ||
lastName: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import "reflect-metadata"; | ||
import { createTestingConnections, closeTestingConnections, reloadTestingDatabases } from "../../utils/test-utils"; | ||
import { Connection } from "../../../src/connection/Connection"; | ||
import { expect } from "chai"; | ||
import { Customer } from "./entity/Customer"; | ||
import { CustomerContact } from "./entity/CustomerContact"; | ||
|
||
|
||
describe("github issues > #8346 MySQL: Regression when using take, orderBy, and getMany on a joined relation", () => { | ||
let connections: Connection[]; | ||
before(async () => connections = await createTestingConnections({ | ||
entities: [__dirname + "/entity/*{.js,.ts}"], | ||
schemaCreate: true, | ||
dropSchema: true, | ||
logging: true | ||
})); | ||
beforeEach(() => reloadTestingDatabases(connections)); | ||
after(() => closeTestingConnections(connections)); | ||
|
||
it("should return customers ordered by contacts", () => Promise.all(connections.map(async connection => { | ||
const [user1, user2] = await connection.getRepository(Customer).save([ | ||
{ name: "userA" }, | ||
{ name: "userB" }, | ||
]); | ||
await connection.getRepository(CustomerContact).save([ | ||
{ firstName: "firstName1", lastName: "lastName1", customer: user1 }, | ||
{ firstName: "firstName2", lastName: "lastName2", customer: user2 }, | ||
]); | ||
|
||
const customerRepository = connection.getRepository(Customer); | ||
|
||
const results = await customerRepository | ||
.createQueryBuilder('customer') | ||
.leftJoinAndSelect('customer.contacts', 'contacts') | ||
.take(10) | ||
.orderBy('contacts.firstName', 'DESC') | ||
.getMany(); | ||
|
||
expect(results[0].id).to.equal(user2.id); | ||
expect(results[1].id).to.equal(user1.id); | ||
}))); | ||
}) |