fix #135 proper relation generation when unique index have more columns

This commit is contained in:
Kononnable 2019-01-06 14:40:38 +01:00
parent 17facf0b2c
commit 31ff9c8bf5
5 changed files with 71 additions and 6 deletions

View File

@ -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;

View 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;
}

View 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[];
}

View 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[];
}

View File

@ -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 {