Permalink
Browse files

fix(SchemaBuilder): Set cascade delete for join table

  • Loading branch information...
RWOverdijk committed Oct 9, 2016
1 parent 0e9e814 commit c7974bd349495500836809f855fa505c88229608
Showing with 8 additions and 6 deletions.
  1. +8 −6 src/SchemaBuilder.ts
@@ -3,7 +3,6 @@ import {EntityInterface, EntityCtor} from './EntityInterface';
import * as Knex from 'knex';
import {Scope} from './Scope';
import {Store} from './Store';
import {index} from './decorators/Mapping';
export class SchemaBuilder {
@@ -287,12 +286,15 @@ export class SchemaBuilder {
table.index(index.columns);
});
table.foreign(foreignColumnsInverse)
.references(referenceColumnsInverse)
.inTable(targetMapping.getTableName())
.onDelete('cascade');
let foreignInverse = table.foreign(foreignColumnsInverse).references(referenceColumnsInverse).inTable(targetMapping.getTableName());
let foreign = table.foreign(referenceColumns).references(foreignColumns).inTable(mapping.getTableName());
this.applyCascades(mapping.getField(property).cascades, foreignInverse);
this.applyCascades(mapping.getField(property).cascades, foreign);
table.foreign(referenceColumns)
.references(foreignColumns)
.inTable(mapping.getTableName())
.onDelete('cascade');
});
});

0 comments on commit c7974bd

Please sign in to comment.