Permalink
Browse files

fix(mapping): make mapping work with fallback column name

  • Loading branch information...
RWOverdijk committed Nov 6, 2016
1 parent 679bc80 commit 714f086ae34c325af380e21892d2f82dc7578dfd
Showing with 19 additions and 3 deletions.
  1. +19 −3 src/Mapping.ts
@@ -188,8 +188,15 @@ export class Mapping<T> {
let toUnderscore = entityManager.getConfig().fetch('mapping.defaultNamesToUnderscore');
let propertyName = toUnderscore ? this.nameToUnderscore(property) : property;
let field = this.mapping.fetchOrPut(`fields.${property}`, {});
Homefront.merge(this.mapping.fetchOrPut(`fields.${property}`, {name: propertyName}), options);
if (field.name) {
this.mapping.remove(`columns.${this.getColumnName(property)}`);
} else {
field.name = propertyName;
}
Homefront.merge(field, options);
this.mapColumn(this.getColumnName(property), property);
@@ -818,9 +825,18 @@ export class Mapping<T> {
* @returns {Mapping}
*/
public extendField(property: string, additional: Object): this {
Homefront.merge(this.mapping.fetchOrPut(`fields.${property}`, {name: property}), additional);
let field = this.mapping.fetchOrPut(`fields.${property}`, {});
let needsName = !field.name;
if (needsName) {
field.name = property;
}
Homefront.merge(field, additional);
this.mapColumn(this.getColumnName(property) || property, property);
if (needsName) {
this.mapColumn(this.getColumnName(property) || property, property);
}
return this;
}

0 comments on commit 714f086

Please sign in to comment.