Permalink
Browse files

feat(Mapping): add `setDefaultCascades` method

  • Loading branch information...
Rawphs
Rawphs committed Apr 10, 2018
1 parent b8c1c6b commit 36364e3223affc559df2c90e54946fc8aacfe4f8
Showing with 24 additions and 4 deletions.
  1. +24 −4 src/Mapping.ts
@@ -676,12 +676,33 @@ export class Mapping<T> {
throw new Error('Required property "targetEntity" not found in options.');
}

this.setDefaultCascades(property);

this.extendField(property, {relationship: options});
Homefront.merge(this.mapping.fetchOrPut('relations', {}), {[property]: options});

return this;
}

/**
* Sets the default cascades if no cascade options exist
*
* @param {string} property
*/
private setDefaultCascades(property: string) {
if (!this.entityManager) {
return;
}

const field = this.getField(property, true);

if (field && typeof field.cascades === 'undefined') {
this.cascade(property, this.entityManager.getConfig().fetch('mapping.defaults.cascades', []));
}

return this;
}

/**
* Does property exist as relation.
*
@@ -943,11 +964,10 @@ export class Mapping<T> {

for (let property in relations) {
let relation = relations[property];
let field = this.getField(property);

if (typeof field.cascades === 'undefined') {
this.cascade(property, manager.getConfig().fetch('mapping.defaults.cascades', []));
}
this.setDefaultCascades(property);

this.cascade(property, this.getField(property).cascades);

// Make sure joinTable is complete.
if (relation.type === Mapping.RELATION_MANY_TO_MANY && relation.inversedBy) {

0 comments on commit 36364e3

Please sign in to comment.