Permalink
Browse files

fix(Mapping): prevent duplicate applied mappings

  • Loading branch information...
RWOverdijk committed Jan 4, 2017
1 parent cdf6880 commit 6a53505e00f66f23f8cb6591f5cf5bce51bb2c54
Showing with 28 additions and 0 deletions.
  1. +28 −0 src/Mapping.ts
@@ -129,6 +129,8 @@ export class Mapping<T> {
this[stagedMapping.method](...stagedMapping.parameters);
});
this.stagedMappings = [];
return this;
}
@@ -290,6 +292,23 @@ export class Mapping<T> {
return this;
}
/**
* Get the field names (property names) from the mapping.
*
* @param {boolean} includeRelations
*/
public getFieldNames(includeRelations: boolean = false): Array<string> {
let fields = this.getFields();
return Reflect.ownKeys(fields).reduce((fieldNames, fieldName) => {
if (!fields[fieldName].relationship || includeRelations) {
fieldNames.push(fieldName);
}
return fieldNames;
}, []);
}
/**
* Map an entity. Examples:
*
@@ -647,6 +666,15 @@ export class Mapping<T> {
return this.mapping.fetch('relations');
}
/**
* Get the relations for mapped entity.
*
* @returns {Relationship}
*/
public getRelation(property: string): Relationship {
return this.mapping.fetch('relations.' + property);
}
/**
* Map a relationship.
*

0 comments on commit 6a53505

Please sign in to comment.