From 61c98f7592c9061eaf1af50b4690f318b939f4e3 Mon Sep 17 00:00:00 2001 From: Kononnable Date: Sun, 10 Nov 2019 23:57:04 +0100 Subject: [PATCH] tests: compare join column options --- .../github-issues/71/entity/PostAuthor.ts | 2 +- .../github-issues/71/entity/PostDetails.ts | 2 +- test/utils/EntityFileToJson.ts | 23 +++++++++++++++++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/test/integration/github-issues/71/entity/PostAuthor.ts b/test/integration/github-issues/71/entity/PostAuthor.ts index b9b01df..b09cd20 100644 --- a/test/integration/github-issues/71/entity/PostAuthor.ts +++ b/test/integration/github-issues/71/entity/PostAuthor.ts @@ -22,7 +22,7 @@ export class PostAuthor { id: number; @OneToOne(type => Post, Post => Post.id, { - onDelete: "CASCADE" + // onDelete: "CASCADE" // onUpdate: "CASCADE" }) @JoinColumn() diff --git a/test/integration/github-issues/71/entity/PostDetails.ts b/test/integration/github-issues/71/entity/PostDetails.ts index 3feb93f..fb4f959 100644 --- a/test/integration/github-issues/71/entity/PostDetails.ts +++ b/test/integration/github-issues/71/entity/PostDetails.ts @@ -22,7 +22,7 @@ export class PostDetails { id: number; @OneToOne(type => Post, Post => Post.id, { - onDelete: "SET NULL" + // onDelete: "SET NULL" // onUpdate: "SET NULL" }) @JoinColumn() diff --git a/test/utils/EntityFileToJson.ts b/test/utils/EntityFileToJson.ts index b9ea9b8..73cd595 100644 --- a/test/utils/EntityFileToJson.ts +++ b/test/utils/EntityFileToJson.ts @@ -15,6 +15,8 @@ class EntityColumn { public columnOptions: { [key: string]: string | boolean } = {}; + public joinOptions: { [key: string]: string | boolean }[] = []; + public relationType: "OneToOne" | "OneToMany" | "ManyToOne" | "ManyToMany"; public isOwnerOfRelation = false; @@ -100,8 +102,8 @@ export default class EntityFileToJson { } else { let badJSON = !primaryGeneratedColumn ? decoratorParameters.substring( - decoratorParameters.indexOf(",") + 1 - ) + decoratorParameters.indexOf(",") + 1 + ) : decoratorParameters; badJSON = badJSON.trim(); if (badJSON.lastIndexOf(",") === badJSON.length - 3) { @@ -400,6 +402,23 @@ export default class EntityFileToJson { retVal.columns[ retVal.columns.length - 1 ].isOwnerOfRelation = true; + const decoratorParameters = trimmedLine + .substring( + trimmedLine.indexOf("(") + 1, + trimmedLine.indexOf(")") + ) + .trim() + .replace(/(['"])?([a-z0-9A-Z_]+)(['"])?:/g, '"$2": '); + if (decoratorParameters.length > 0) { + const column = + retVal.columns[retVal.columns.length - 1]; + const options = JSON.parse(decoratorParameters); + if (Array.isArray(options)) { + column.joinOptions = options as any; + } else { + column.joinOptions = [options] as any; + } + } } return; }