diff --git a/src/drivers/AbstractDriver.ts b/src/drivers/AbstractDriver.ts index fb577ee..889f291 100644 --- a/src/drivers/AbstractDriver.ts +++ b/src/drivers/AbstractDriver.ts @@ -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( diff --git a/src/entity.mst b/src/entity.mst index 0c7f940..cb9fcac 100644 --- a/src/entity.mst +++ b/src/entity.mst @@ -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}}; diff --git a/test/integration/github-issues/117/entity/Post.ts b/test/integration/github-issues/117/entity/Post.ts new file mode 100644 index 0000000..b408da2 --- /dev/null +++ b/test/integration/github-issues/117/entity/Post.ts @@ -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; +} diff --git a/test/integration/github-issues/117/entity/Section.ts b/test/integration/github-issues/117/entity/Section.ts new file mode 100644 index 0000000..b67b276 --- /dev/null +++ b/test/integration/github-issues/117/entity/Section.ts @@ -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; +} diff --git a/test/utils/EntityFileToJson.ts b/test/utils/EntityFileToJson.ts index b73df1f..afb861a 100644 --- a/test/utils/EntityFileToJson.ts +++ b/test/utils/EntityFileToJson.ts @@ -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;