diff --git a/test/integration/examples/sample2-one-to-one/entity/Post.ts b/test/integration/examples/sample2-one-to-one/entity/Post.ts index 59b47ce..c68dad6 100644 --- a/test/integration/examples/sample2-one-to-one/entity/Post.ts +++ b/test/integration/examples/sample2-one-to-one/entity/Post.ts @@ -20,8 +20,8 @@ export class Post { // post has relation with category, however inverse relation is not set (category does not have relation with post set) @OneToOne(type => PostCategory, { - cascade: true, - onDelete: 'CASCADE' + // cascade: true, + // onDelete: 'CASCADE' }) @JoinColumn() // @Index({ unique: true }) @@ -30,7 +30,7 @@ export class Post { // post has relation with details. cascade inserts here means if new PostDetails instance will be set to this // relation it will be inserted automatically to the db when you save this Post entity @OneToOne(type => PostDetails, details => details.post, { - cascade: true + // cascade: true }) @JoinColumn() // @Index({ unique: true }) @@ -39,7 +39,7 @@ export class Post { // post has relation with details. cascade update here means if new PostDetail instance will be set to this relation // it will be inserted automatically to the db when you save this Post entity @OneToOne(type => PostImage, image => image.post, { - cascade: true, + // cascade: true, }) @JoinColumn() // @Index({ unique: true }) @@ -48,7 +48,7 @@ export class Post { // post has relation with details. cascade update here means if new PostDetail instance will be set to this relation // it will be inserted automatically to the db when you save this Post entity @OneToOne(type => PostMetadata, metadata => metadata.post, { - onDelete: 'CASCADE' + // onDelete: 'CASCADE' }) @JoinColumn() // @Index({ unique: true }) @@ -56,8 +56,8 @@ export class Post { // post has relation with details. full cascades here @OneToOne(type => PostInformation, information => information.post, { - cascade: true, - onDelete: 'CASCADE' + // cascade: true, + // onDelete: 'CASCADE' }) @JoinColumn() // @Index({ unique: true }) diff --git a/test/integration/examples/sample2-one-to-one/entity/PostDetails.ts b/test/integration/examples/sample2-one-to-one/entity/PostDetails.ts index b68e075..0ac9f6a 100644 --- a/test/integration/examples/sample2-one-to-one/entity/PostDetails.ts +++ b/test/integration/examples/sample2-one-to-one/entity/PostDetails.ts @@ -18,7 +18,7 @@ export class PostDetails { @OneToOne(type => Post, post => post.details, { // cascade: true, - onDelete: 'CASCADE' + // onDelete: 'CASCADE' }) post: Post; diff --git a/test/utils/EntityFileToJson.ts b/test/utils/EntityFileToJson.ts index 603cefe..4fae927 100644 --- a/test/utils/EntityFileToJson.ts +++ b/test/utils/EntityFileToJson.ts @@ -1,4 +1,5 @@ import { debug } from "util"; +import { param } from "change-case"; export class EntityFileToJson { getEntityOptions(trimmedLine: string, ent: EntityJson) { @@ -51,6 +52,21 @@ export class EntityFileToJson { } } } + getRelationOptions(trimmedLine:string, col:EntityColumn){ + let decoratorParameters = trimmedLine.slice(trimmedLine.indexOf('(') + 1, trimmedLine.lastIndexOf(')')) + if (decoratorParameters.length > 0) { + let params = decoratorParameters.match(/(,)(?!([^{]*}))/g) + if ( params && params.length == 2) { + let badJSON = decoratorParameters.substring( decoratorParameters.lastIndexOf('{'),decoratorParameters.lastIndexOf('}')+1).trim() + if (badJSON.lastIndexOf(',') == badJSON.length - 3) { + badJSON = badJSON.slice(0, badJSON.length - 3) + badJSON[badJSON.length - 2] + badJSON[badJSON.length - 1] + } + col.columnOptions = JSON.parse(badJSON.replace(/(')/g,`"`).replace(/(['"])?([a-z0-9A-Z_]+)(['"])?:/g, '"$2": ')) + } else { + + } + } + } getIndexOptions(trimmedLine: string, ind: EntityIndex) { let decoratorParameters = trimmedLine.slice(trimmedLine.indexOf('(') + 1, trimmedLine.lastIndexOf(')')) @@ -247,6 +263,7 @@ export class EntityFileToJson { let column = new EntityColumn() retVal.columns.push(column) column.relationType = "OneToOne" + this.getRelationOptions(trimmedLine,column); continue; } } else if (trimmedLine.startsWith('@JoinColumn')) {