complex relationships support
This commit is contained in:
parent
d1407ab5d9
commit
9c546dfdef
@ -259,16 +259,16 @@ export default abstract class AbstractDriver {
|
||||
const relatedTable = entities.find(
|
||||
entity => entity.tscName === relationTmp.ownerTable.tscName
|
||||
)!;
|
||||
if (
|
||||
relatedTable.columns.length !==
|
||||
relationTmp.ownerColumns.length * 2
|
||||
) {
|
||||
TomgUtils.LogError(
|
||||
`Relation between tables ${relationTmp.ownerTable.sqlName} and ${relationTmp.relatedTable.sqlName} wasn't generated correctly - complex relationships aren't supported yet.`,
|
||||
false
|
||||
);
|
||||
return;
|
||||
}
|
||||
// if (
|
||||
// relatedTable.columns.length !==
|
||||
// relationTmp.ownerColumns.length * 2
|
||||
// ) {
|
||||
// TomgUtils.LogError(
|
||||
// `Relation between tables ${relationTmp.ownerTable.sqlName} and ${relationTmp.relatedTable.sqlName} wasn't generated correctly - complex relationships aren't supported yet.`,
|
||||
// false
|
||||
// );
|
||||
// return;
|
||||
// }
|
||||
|
||||
const secondRelation = relationsTemp.find(
|
||||
relation =>
|
||||
@ -276,13 +276,13 @@ export default abstract class AbstractDriver {
|
||||
relation.relatedTable.tscName !==
|
||||
relationTmp.relatedTable.tscName
|
||||
)!;
|
||||
if (!secondRelation) {
|
||||
TomgUtils.LogError(
|
||||
`Relation between tables ${relationTmp.ownerTable.sqlName} and ${relationTmp.relatedTable.sqlName} wasn't generated correctly - complex relationships aren't supported yet.`,
|
||||
false
|
||||
);
|
||||
return;
|
||||
}
|
||||
// if (!secondRelation) {
|
||||
// TomgUtils.LogError(
|
||||
// `Relation between tables ${relationTmp.ownerTable.sqlName} and ${relationTmp.relatedTable.sqlName} wasn't generated correctly - complex relationships aren't supported yet.`,
|
||||
// false
|
||||
// );
|
||||
// return;
|
||||
// }
|
||||
}
|
||||
|
||||
const ownerEntity = entities.find(
|
||||
|
@ -11,7 +11,7 @@ import { {{toEntityName .}} } from './{{toFileName .}}'
|
||||
{{/inline}}
|
||||
{{#*inline "Relation"}}
|
||||
@{{relationType}}(()=>{{toEntityName relatedTable}},{{toEntityName relatedTable}}=>{{toEntityName relatedTable}}.{{toPropertyName relatedField}}{{#if relationOptions}},{ {{json relationOptions}} }{{/if}})
|
||||
{{#if joinColumnOptions}}@JoinColumn({{json joinColumnOptions}}){{/if}}
|
||||
{{#if joinColumnOptions}}@JoinColumn([{{json joinColumnOptions}}]){{/if}}
|
||||
{{#if joinTableOptions}}@JoinTable({ {{json joinTableOptions}} }){{/if}}
|
||||
{{toPropertyName fieldName}}:{{toRelation (toEntityName relatedTable) relationType}};
|
||||
|
||||
|
29
test/integration/github-issues/117/entity/Post.ts
Normal file
29
test/integration/github-issues/117/entity/Post.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import {
|
||||
Index,
|
||||
Entity,
|
||||
PrimaryColumn,
|
||||
Column,
|
||||
OneToOne,
|
||||
OneToMany,
|
||||
ManyToOne,
|
||||
ManyToMany,
|
||||
JoinColumn,
|
||||
JoinTable
|
||||
} from "typeorm";
|
||||
import { Section } from "./Section";
|
||||
|
||||
@Entity("Post")
|
||||
export class Post {
|
||||
@Column("int", {
|
||||
primary: true,
|
||||
name: "Id"
|
||||
})
|
||||
id: number;
|
||||
|
||||
@OneToOne(type => Section, section => section.post)
|
||||
@JoinColumn([
|
||||
{ name: "work", referencedColumnName: "work" },
|
||||
{ name: "section", referencedColumnName: "section" }
|
||||
])
|
||||
section: Section;
|
||||
}
|
32
test/integration/github-issues/117/entity/Section.ts
Normal file
32
test/integration/github-issues/117/entity/Section.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import {
|
||||
Index,
|
||||
Entity,
|
||||
PrimaryColumn,
|
||||
Column,
|
||||
OneToOne,
|
||||
OneToMany,
|
||||
ManyToOne,
|
||||
ManyToMany,
|
||||
JoinColumn,
|
||||
JoinTable,
|
||||
RelationId
|
||||
} from "typeorm";
|
||||
import { Post } from "./Post";
|
||||
|
||||
@Entity("Section")
|
||||
export class Section {
|
||||
@Column("int", {
|
||||
primary: true,
|
||||
name: "work"
|
||||
})
|
||||
work: number;
|
||||
|
||||
@Column("int", {
|
||||
primary: true,
|
||||
name: "section"
|
||||
})
|
||||
section: number;
|
||||
|
||||
@OneToOne(type => Post, Post => Post.id)
|
||||
post: Post;
|
||||
}
|
@ -405,6 +405,7 @@ export default class EntityFileToJson {
|
||||
priorPartOfMultilineStatement = trimmedLine;
|
||||
} else {
|
||||
isMultilineStatement = false;
|
||||
// TODO: get joinColumnOptions options
|
||||
retVal.columns[
|
||||
retVal.columns.length - 1
|
||||
].isOwnerOfRelation = true;
|
||||
@ -417,6 +418,7 @@ export default class EntityFileToJson {
|
||||
priorPartOfMultilineStatement = trimmedLine;
|
||||
} else {
|
||||
isMultilineStatement = false;
|
||||
// TODO: get joinTableOptions options - is it possible while JoinTable can be on either side of the relationship?
|
||||
// it doesn't matter which side of ManyToMany relation is marked as owner
|
||||
}
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user