fix #135 proper relation generation when unique index have more columns
This commit is contained in:
parent
17facf0b2c
commit
31ff9c8bf5
@ -358,9 +358,8 @@ export abstract class AbstractDriver {
|
||||
const index = ownerEntity.Indexes.find(
|
||||
ind =>
|
||||
ind.isUnique &&
|
||||
ind.columns.some(
|
||||
col => col.name === ownerColumn!.tsName
|
||||
)
|
||||
ind.columns.length === 1 &&
|
||||
ind.columns[0].name === ownerColumn!.tsName
|
||||
);
|
||||
isOneToMany = !index;
|
||||
|
||||
|
26
test/integration/github-issues/135/entity/Post.ts
Normal file
26
test/integration/github-issues/135/entity/Post.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import { Index, Entity, PrimaryColumn, Column, OneToOne, OneToMany, ManyToOne, ManyToMany, JoinColumn, JoinTable } from "typeorm";
|
||||
import { PostAuthor } from "./PostAuthor";
|
||||
import { PostCategory } from "./PostCategory";
|
||||
|
||||
|
||||
@Index("travel_travelplanextra_travel_plan_id_extra_id_f825ca51_uniq",["postAuthor","postCategory",],{unique:true})
|
||||
@Entity("Post")
|
||||
export class Post {
|
||||
|
||||
@Column("int", {
|
||||
nullable: false,
|
||||
primary: true,
|
||||
name: "Id"
|
||||
})
|
||||
Id: number;
|
||||
|
||||
@ManyToOne(type => PostAuthor, PostAuthor => PostAuthor.Id)
|
||||
@JoinColumn()
|
||||
postAuthor: PostAuthor;
|
||||
|
||||
|
||||
@ManyToOne(type => PostCategory, PostCategory => PostCategory.Id)
|
||||
@JoinColumn()
|
||||
postCategory: PostCategory;
|
||||
|
||||
}
|
20
test/integration/github-issues/135/entity/PostAuthor.ts
Normal file
20
test/integration/github-issues/135/entity/PostAuthor.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import {Index,Entity, PrimaryColumn, Column, OneToOne, OneToMany, ManyToOne, ManyToMany, JoinColumn, JoinTable, RelationId} from "typeorm";
|
||||
import { Post } from "./Post";
|
||||
|
||||
|
||||
@Entity("PostAuthor")
|
||||
export class PostAuthor {
|
||||
|
||||
@Column("int",{
|
||||
nullable:false,
|
||||
primary:true,
|
||||
name:"Id"
|
||||
})
|
||||
Id:number;
|
||||
|
||||
|
||||
|
||||
@OneToMany(type => Post, Post => Post.Id)
|
||||
posts:Post[];
|
||||
|
||||
}
|
20
test/integration/github-issues/135/entity/PostCategory.ts
Normal file
20
test/integration/github-issues/135/entity/PostCategory.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import {Index,Entity, PrimaryColumn, Column, OneToOne, OneToMany, ManyToOne, ManyToMany, JoinColumn, JoinTable, RelationId} from "typeorm";
|
||||
import { Post } from "./Post";
|
||||
|
||||
|
||||
@Entity("PostCategory")
|
||||
export class PostCategory {
|
||||
|
||||
@Column("int",{
|
||||
nullable:false,
|
||||
primary:true,
|
||||
name:"Id"
|
||||
})
|
||||
Id:number;
|
||||
|
||||
|
||||
|
||||
@OneToMany(type => Post, Post => Post.Id)
|
||||
posts:Post[];
|
||||
|
||||
}
|
@ -4,9 +4,9 @@ import {quests} from "./quests";
|
||||
|
||||
|
||||
@Entity("feedextrainfo")
|
||||
@Index("feedExtraInfo_FeedOwnerId_idx",["feedOwnerId",])
|
||||
@Index("feedExtraInfo_ReaderId_idx",["readerId",])
|
||||
@Index("feedExtraInfo_QuestId_idx",["questId",])
|
||||
@Index("feedExtraInfo_FeedOwnerId_idx",["feedOwnerId",],{unique:true})
|
||||
@Index("feedExtraInfo_ReaderId_idx",["readerId",],{unique:true})
|
||||
@Index("feedExtraInfo_QuestId_idx",["questId",],{unique:true})
|
||||
export class feedextrainfo {
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user