added multiple relations on single column
This commit is contained in:
parent
fcf593e3ae
commit
9f5d0eee03
@ -45,6 +45,7 @@ export class MssqlDriver extends AbstractDriver {
|
||||
}).forEach((resp) => {
|
||||
let colInfo: ColumnInfo = <ColumnInfo>{};
|
||||
colInfo.name = resp.COLUMN_NAME;
|
||||
colInfo.relations=[];
|
||||
colInfo.is_nullable = resp.IS_NULLABLE == 'YES' ? true : false;
|
||||
colInfo.default = resp.COLUMN_DEFAULT;
|
||||
switch (resp.DATA_TYPE) {
|
||||
@ -276,21 +277,21 @@ order by
|
||||
isOneToMany=false;
|
||||
}
|
||||
|
||||
ownerColumn.relation=<RelationInfo>{
|
||||
ownerColumn.relations.push(<RelationInfo>{
|
||||
actionOnDelete:relationTmp.actionOnDelete,
|
||||
isOwner:true,
|
||||
relatedColumn:relatedColumn.name,
|
||||
relatedTable:relationTmp.referencedTable,
|
||||
relationType:isOneToMany?"OneToMany":"OneToOne"
|
||||
}
|
||||
relatedColumn.relation=<RelationInfo>{
|
||||
})
|
||||
relatedColumn.relations.push(<RelationInfo>{
|
||||
actionOnDelete:relationTmp.actionOnDelete,
|
||||
isOwner:false,
|
||||
relatedColumn:ownerColumn.name,
|
||||
relatedTable:relationTmp.ownerTable,
|
||||
relationType:isOneToMany?"ManyToOne":"OneToOne"
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
return entities;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import {Index,Entity, PrimaryColumn, Column, OneToOne, OneToMany, ManyToOne, JoinTable} from "typeorm";
|
||||
{{#Columns}}{{#relation}}import{ {{relatedTable}} } from "./{{relatedTable}}";
|
||||
{{/relation}}{{/Columns}}
|
||||
{{#Columns}}{{#relations}}import{ {{relatedTable}} } from "./{{relatedTable}}";
|
||||
{{/relations}}{{/Columns}}
|
||||
|
||||
@Entity()
|
||||
{{#Indexes}}{{^isPrimaryKey}}@Index("{{name}}",[{{#columns}}"{{name}}",{{/columns}}]{{#isUnique}},{unique:true}{{/isUnique}})
|
||||
@ -8,9 +8,9 @@ import {Index,Entity, PrimaryColumn, Column, OneToOne, OneToMany, ManyToOne, Joi
|
||||
|
||||
{{#Columns}}
|
||||
|
||||
@Column("{{sql_type}}",{ {{#is_nullable}}nullable:true,{{/is_nullable}}{{#char_max_lenght}}length:{{char_max_lenght}},{{/char_max_lenght}}{{#default}}default:{{default}},{{/default}}{{#numericPrecision}}precision:{numericPrecision},{{/numericPrecision}}{{#numericScale}}scale:{{numericScale}},{{/numericScale}}{{#isPrimary}}primary:{{isPrimary}},{{/isPrimary}}}){{#relation}}
|
||||
@Column("{{sql_type}}",{ {{#is_nullable}}nullable:true,{{/is_nullable}}{{#char_max_lenght}}length:{{char_max_lenght}},{{/char_max_lenght}}{{#default}}default:{{default}},{{/default}}{{#numericPrecision}}precision:{numericPrecision},{{/numericPrecision}}{{#numericScale}}scale:{{numericScale}},{{/numericScale}}{{#isPrimary}}primary:{{isPrimary}},{{/isPrimary}}}){{#relations}}
|
||||
@{{relationType}}(type=>{{relatedTable}},x=>x.{{relatedColumn}}){{#isOwner}}
|
||||
@JoinTable(){{/isOwner}}{{/relation}}
|
||||
@JoinTable(){{/isOwner}}{{/relations}}
|
||||
{{name}}:{{ts_type}};
|
||||
{{/Columns}}
|
||||
}
|
@ -12,7 +12,7 @@ interface ColumnInfo {
|
||||
isPrimary:boolean,
|
||||
numericPrecision:number|null,
|
||||
numericScale:number|null,
|
||||
relation:RelationInfo
|
||||
relations:RelationInfo[]
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user