-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Error when sorting by an embedded entity while using join and sk…
- Loading branch information
Showing
3 changed files
with
113 additions
and
4 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 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,43 @@ | ||
import { Column, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn } from "../../../src"; | ||
|
||
|
||
@Entity() | ||
export class User { | ||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column() | ||
name: string; | ||
|
||
@OneToMany( | ||
() => Post, | ||
(post) => post.user, | ||
) | ||
posts: Post[]; | ||
} | ||
|
||
export class PublishInfo { | ||
@Column({ nullable: true }) | ||
date: Date; | ||
} | ||
|
||
@Entity() | ||
export class Post { | ||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column() | ||
text: string; | ||
|
||
@Column(_type => PublishInfo) | ||
blog: PublishInfo; | ||
|
||
@Column(_type => PublishInfo) | ||
newsletter: PublishInfo; | ||
|
||
@ManyToOne( | ||
() => User, | ||
(user) => user.posts, | ||
) | ||
user: User | ||
} |
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,62 @@ | ||
import "reflect-metadata"; | ||
import { createTestingConnections, closeTestingConnections, reloadTestingDatabases } from "../../utils/test-utils"; | ||
import { Connection } from "../../../src/connection/Connection"; | ||
import { expect } from "chai"; | ||
import {Post, User} from "./entities" | ||
|
||
describe("github issues > #7079 Error when sorting by an embedded entity while using join and skip/take", () => { | ||
|
||
let connections: Connection[]; | ||
before(async () => connections = await createTestingConnections({ | ||
entities: [Post, User], | ||
schemaCreate: true, | ||
dropSchema: true, | ||
})); | ||
beforeEach(() => reloadTestingDatabases(connections)); | ||
after(() => closeTestingConnections(connections)); | ||
|
||
it("should be able to getMany with join and sorting by an embedded entity column while user take and skip", () => Promise.all(connections.map(async connection => { | ||
const postRepo = connection.getRepository(Post) | ||
const userRepo = connection.getRepository(User) | ||
|
||
const users = [ | ||
{ id: 1, name: "Mike" }, | ||
{ id: 2, name: "Alice" } | ||
] | ||
await userRepo.save(users) | ||
|
||
const posts = [ | ||
{ | ||
id: 1, | ||
text: "Happy Holidays", | ||
userId: 1, | ||
blog: { date: new Date().toISOString() }, | ||
newsletter: { date: new Date().toISOString() } | ||
}, | ||
{ | ||
id: 2, | ||
text: "My Vacation", | ||
userId: 1, | ||
blog: { date: new Date().toISOString() }, | ||
newsletter: { date: new Date().toISOString() } | ||
}, | ||
{ | ||
id: 3, | ||
text: "Working with TypeORM", | ||
userId: 2, | ||
blog: { date: new Date().toISOString() }, | ||
newsletter: { date: new Date().toISOString() } | ||
} | ||
] | ||
await postRepo.save(posts); | ||
|
||
const result = await postRepo.createQueryBuilder("post") | ||
.leftJoinAndSelect("post.user", "user") | ||
.orderBy("post.blog.date") | ||
.take(2) | ||
.skip(1) | ||
.getMany(); | ||
expect(result.length).eq(2); | ||
}))); | ||
|
||
}); |