-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: allow where IsNull for ManyToOne relations (#9031)
* fix: allow where IsNull for ManyToOne relations Closes: #8890 * fix direct FindOperator queries on MTO relation * fix: allow FindOperator queries on OTO owner column * chore: prettier formating
- Loading branch information
Showing
7 changed files
with
422 additions
and
0 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,20 @@ | ||
import { Column, Entity, OneToMany, PrimaryColumn } from "../../../../src" | ||
import { Post } from "./Post" | ||
|
||
@Entity() | ||
export class Author { | ||
@PrimaryColumn() | ||
id: number | ||
|
||
@Column() | ||
firstName: string | ||
|
||
@Column() | ||
lastName: string | ||
|
||
@Column() | ||
age: number | ||
|
||
@OneToMany(() => Post, (post) => post.author) | ||
posts: Post[] | ||
} |
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,24 @@ | ||
import { | ||
Column, | ||
Entity, | ||
ManyToOne, | ||
PrimaryGeneratedColumn, | ||
} from "../../../../src" | ||
import { Author } from "./Author" | ||
|
||
@Entity() | ||
export class Post { | ||
@PrimaryGeneratedColumn() | ||
id: number | ||
|
||
@Column() | ||
title: string | ||
|
||
@Column() | ||
text: string | ||
|
||
@ManyToOne(() => Author, (author) => author.posts, { | ||
nullable: true, | ||
}) | ||
author: Author | null | ||
} |
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,10 @@ | ||
import { Column, Entity, PrimaryGeneratedColumn } from "../../../../src" | ||
|
||
@Entity() | ||
export class Profile { | ||
@PrimaryGeneratedColumn() | ||
id: number | ||
|
||
@Column() | ||
image: 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,23 @@ | ||
import { | ||
Column, | ||
Entity, | ||
OneToOne, | ||
JoinColumn, | ||
PrimaryColumn, | ||
} from "../../../../src" | ||
import { Profile } from "./Profile" | ||
|
||
@Entity() | ||
export class User { | ||
@PrimaryColumn() | ||
id: number | ||
|
||
@Column() | ||
username: string | ||
|
||
@OneToOne(() => Profile, { | ||
nullable: true, | ||
}) | ||
@JoinColumn() | ||
profile: Profile | null | ||
} |
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,95 @@ | ||
import "reflect-metadata" | ||
import { EntityManager } from "../../../src" | ||
import { Post } from "./entity/Post" | ||
import { Author } from "./entity/Author" | ||
import { Profile } from "./entity/Profile" | ||
import { User } from "./entity/User" | ||
|
||
export async function prepareDataManyToOne(manager: EntityManager) { | ||
const author1 = new Author() | ||
author1.id = 1 | ||
author1.firstName = "Timber" | ||
author1.lastName = "Saw" | ||
author1.age = 25 | ||
|
||
const author2 = new Author() | ||
author2.id = 2 | ||
author2.firstName = "Bob" | ||
author2.lastName = "Miller" | ||
author2.age = 34 | ||
|
||
const author3 = new Author() | ||
author3.id = 3 | ||
author3.firstName = "Max" | ||
author3.lastName = "Newton" | ||
author3.age = 54 | ||
|
||
await manager.save([author1, author2, author3]) | ||
|
||
const post1 = new Post() | ||
post1.id = 1 | ||
post1.title = "Post #1" | ||
post1.text = "About post #1" | ||
post1.author = author1 | ||
|
||
const post2 = new Post() | ||
post2.id = 2 | ||
post2.title = "Post #2" | ||
post2.text = "About post #2" | ||
|
||
const post3 = new Post() | ||
post3.id = 3 | ||
post3.title = "Post #3" | ||
post3.text = "About post #3" | ||
|
||
const post4 = new Post() | ||
post4.id = 4 | ||
post4.title = "Post #4" | ||
post4.text = "About post #4" | ||
post4.author = author2 | ||
|
||
const post5 = new Post() | ||
post5.id = 5 | ||
post5.title = "Post #5" | ||
post5.text = "About post #5" | ||
post5.author = author3 | ||
|
||
await manager.save([post1, post2, post3, post4, post5]) | ||
} | ||
|
||
export async function prepareDataOneToOne(manager: EntityManager) { | ||
const profile1 = new Profile() | ||
profile1.id = 1 | ||
profile1.image = "image-1.jpg" | ||
|
||
const profile2 = new Profile() | ||
profile2.id = 2 | ||
profile2.image = "image-2.jpg" | ||
|
||
const profile3 = new Profile() | ||
profile3.id = 3 | ||
profile3.image = "image-3.jpg" | ||
|
||
await manager.save([profile1, profile2, profile3]) | ||
|
||
const user1 = new User() | ||
user1.id = 1 | ||
user1.username = "user #1" | ||
user1.profile = profile1 | ||
|
||
const user2 = new User() | ||
user2.id = 2 | ||
user2.username = "user #2" | ||
user2.profile = profile2 | ||
|
||
const user3 = new User() | ||
user3.id = 3 | ||
user3.username = "user #3" | ||
user3.profile = profile3 | ||
|
||
const user4 = new User() | ||
user4.id = 4 | ||
user4.username = "user #4" | ||
|
||
await manager.save([user1, user2, user3, user4]) | ||
} |
Oops, something went wrong.