Relational Integrity support #47
This commit is contained in:
parent
c7bc52846f
commit
2782efb694
@ -284,8 +284,8 @@ ORDER BY
|
||||
ForeignKeyColumn: string;
|
||||
TableReferenced: string;
|
||||
ForeignKeyColumnReferenced: string;
|
||||
onDelete: "RESTRICT" | "CASCADE" | "SET NULL";
|
||||
onUpdate: "RESTRICT" | "CASCADE" | "SET NULL";
|
||||
onDelete: "RESTRICT" | "CASCADE" | "SET NULL" | "NO_ACTION";
|
||||
onUpdate: "RESTRICT" | "CASCADE" | "SET NULL" | "NO_ACTION";
|
||||
object_id: number;
|
||||
}[] = (await request.query(`select
|
||||
parentTable.name as TableWithForeignKey,
|
||||
@ -323,8 +323,10 @@ order by
|
||||
rels = <RelationTempInfo>{};
|
||||
rels.ownerColumnsNames = [];
|
||||
rels.referencedColumnsNames = [];
|
||||
rels.actionOnDelete = resp.onDelete;
|
||||
rels.actionOnUpdate = resp.onUpdate;
|
||||
rels.actionOnDelete =
|
||||
resp.onDelete == "NO_ACTION" ? null : resp.onDelete;
|
||||
rels.actionOnUpdate =
|
||||
resp.onUpdate == "NO_ACTION" ? null : resp.onUpdate;
|
||||
rels.object_id = resp.object_id;
|
||||
rels.ownerTable = resp.TableWithForeignKey;
|
||||
rels.referencedTable = resp.TableReferenced;
|
||||
|
@ -277,8 +277,8 @@ export class MysqlDriver extends AbstractDriver {
|
||||
ForeignKeyColumn: string;
|
||||
TableReferenced: string;
|
||||
ForeignKeyColumnReferenced: string;
|
||||
onDelete: "RESTRICT" | "CASCADE" | "SET NULL";
|
||||
onUpdate: "RESTRICT" | "CASCADE" | "SET NULL";
|
||||
onDelete: "RESTRICT" | "CASCADE" | "SET NULL" | "NO_ACTION";
|
||||
onUpdate: "RESTRICT" | "CASCADE" | "SET NULL" | "NO_ACTION";
|
||||
object_id: string;
|
||||
}>(`SELECT
|
||||
CU.TABLE_NAME TableWithForeignKey,
|
||||
@ -306,8 +306,10 @@ export class MysqlDriver extends AbstractDriver {
|
||||
rels = <RelationTempInfo>{};
|
||||
rels.ownerColumnsNames = [];
|
||||
rels.referencedColumnsNames = [];
|
||||
rels.actionOnDelete = resp.onDelete;
|
||||
rels.actionOnUpdate = resp.onUpdate;
|
||||
rels.actionOnDelete =
|
||||
resp.onDelete == "NO_ACTION" ? null : resp.onDelete;
|
||||
rels.actionOnUpdate =
|
||||
resp.onUpdate == "NO_ACTION" ? null : resp.onUpdate;
|
||||
rels.object_id = resp.object_id;
|
||||
rels.ownerTable = resp.TableWithForeignKey;
|
||||
rels.referencedTable = resp.TableReferenced;
|
||||
|
@ -273,8 +273,9 @@ export class OracleDriver extends AbstractDriver {
|
||||
rels = <RelationTempInfo>{};
|
||||
rels.ownerColumnsNames = [];
|
||||
rels.referencedColumnsNames = [];
|
||||
rels.actionOnDelete = resp.DELETE_RULE;
|
||||
rels.actionOnUpdate = "NO ACTION";
|
||||
rels.actionOnDelete =
|
||||
resp.DELETE_RULE == "NO ACTION" ? null : resp.DELETE_RULE;
|
||||
rels.actionOnUpdate = null;
|
||||
rels.object_id = resp.CONSTRAINT_NAME;
|
||||
rels.ownerTable = resp.OWNER_TABLE_NAME;
|
||||
rels.referencedTable = resp.CHILD_TABLE_NAME;
|
||||
|
@ -394,8 +394,8 @@ export class PostgresDriver extends AbstractDriver {
|
||||
att2.attname AS foreignkeycolumn,
|
||||
cl.relname AS tablereferenced,
|
||||
att.attname AS foreignkeycolumnreferenced,
|
||||
update_rule as ondelete,
|
||||
delete_rule as onupdate,
|
||||
delete_rule as ondelete,
|
||||
update_rule as onupdate,
|
||||
con.conname as object_id
|
||||
FROM (
|
||||
SELECT
|
||||
@ -435,8 +435,10 @@ export class PostgresDriver extends AbstractDriver {
|
||||
rels = <RelationTempInfo>{};
|
||||
rels.ownerColumnsNames = [];
|
||||
rels.referencedColumnsNames = [];
|
||||
rels.actionOnDelete = resp.ondelete;
|
||||
rels.actionOnUpdate = resp.onupdate;
|
||||
rels.actionOnDelete =
|
||||
resp.ondelete == "NO ACTION" ? null : resp.ondelete;
|
||||
rels.actionOnUpdate =
|
||||
resp.onupdate == "NO ACTION" ? null : resp.onupdate;
|
||||
rels.object_id = resp.object_id;
|
||||
rels.ownerTable = resp.tablewithforeignkey;
|
||||
rels.referencedTable = resp.tablereferenced;
|
||||
|
@ -24,7 +24,7 @@ import {Index,Entity, PrimaryColumn, Column, OneToOne, OneToMany, ManyToOne, Man
|
||||
})
|
||||
{{toPropertyName name}}:{{ts_type}};
|
||||
{{/relations}}{{#relations}}
|
||||
@{{relationType}}(type=>{{toEntityName relatedTable}}, {{toPropertyName ../name}}=>{{toPropertyName ../name}}.{{#if isOwner}}{{toPropertyName ownerColumn}}{{#../isPrimary}},{primary:true{{^is_nullable}}, nullable:false,{{/is_nullable}} }{{/../isPrimary}}{{else}}{{toPropertyName relatedColumn}}{{/if}}){{#isOwner}}
|
||||
@{{relationType}}(type=>{{toEntityName relatedTable}}, {{toPropertyName ../name}}=>{{toPropertyName ../name}}.{{#if isOwner}}{{toPropertyName ownerColumn}},{ {{#../isPrimary}}primary:true,{{/../isPrimary}}{{^../is_nullable}} nullable:false,{{/../is_nullable}}{{#actionOnDelete}}onDelete: '{{.}}'{{/actionOnDelete}} }{{else}}{{toPropertyName relatedColumn}}{{#actionOnDelete}},{ onDelete: '{{.}}' }{{/actionOnDelete}}{{/if}}){{#isOwner}}
|
||||
{{#if isManyToMany}}@JoinTable(){{else}}@JoinColumn({ name:'{{ ../name}}'}){{/if}}{{/isOwner}}
|
||||
{{#if (or isOneToMany isManyToMany)}}{{toPropertyName ../name}}:{{toEntityName relatedTable}}[];
|
||||
{{else}}{{toPropertyName ../name}}:{{toEntityName relatedTable}};
|
||||
|
@ -7,8 +7,8 @@ export class RelationInfo {
|
||||
relatedColumn: string;
|
||||
ownerTable: string;
|
||||
ownerColumn: string;
|
||||
actionOnDelete: "RESTRICT" | "CASCADE" | "SET NULL" | "NO ACTION";
|
||||
actionOnUpdate: "RESTRICT" | "CASCADE" | "SET NULL" | "NO ACTION";
|
||||
actionOnDelete: "RESTRICT" | "CASCADE" | "SET NULL" | null;
|
||||
actionOnUpdate: "RESTRICT" | "CASCADE" | "SET NULL" | null;
|
||||
|
||||
get isOneToMany(): boolean {
|
||||
return this.relationType == "OneToMany";
|
||||
|
@ -3,7 +3,7 @@ interface RelationTempInfo {
|
||||
ownerColumnsNames: string[];
|
||||
referencedTable: string;
|
||||
referencedColumnsNames: string[];
|
||||
actionOnDelete: "RESTRICT" | "CASCADE" | "SET NULL" | "NO ACTION";
|
||||
actionOnUpdate: "RESTRICT" | "CASCADE" | "SET NULL" | "NO ACTION";
|
||||
actionOnDelete: "RESTRICT" | "CASCADE" | "SET NULL" | null;
|
||||
actionOnUpdate: "RESTRICT" | "CASCADE" | "SET NULL" | null;
|
||||
object_id: number | string;
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ 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'
|
||||
onDelete: 'CASCADE'
|
||||
})
|
||||
@JoinColumn()
|
||||
// @Index({ unique: true })
|
||||
@ -30,7 +30,8 @@ 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
|
||||
onDelete: 'CASCADE'
|
||||
// cascade: true
|
||||
})
|
||||
@JoinColumn()
|
||||
// @Index({ unique: true })
|
||||
@ -48,7 +49,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 })
|
||||
@ -57,7 +58,7 @@ export class Post {
|
||||
// post has relation with details. full cascades here
|
||||
@OneToOne(type => PostInformation, information => information.post, {
|
||||
// cascade: true,
|
||||
// onDelete: 'CASCADE'
|
||||
onDelete: 'CASCADE'
|
||||
})
|
||||
@JoinColumn()
|
||||
// @Index({ unique: true })
|
||||
|
@ -18,7 +18,6 @@ export class PostDetails {
|
||||
|
||||
@OneToOne(type => Post, post => post.details, {
|
||||
// cascade: true,
|
||||
// onDelete: 'CASCADE'
|
||||
})
|
||||
post: Post;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user