Skip to content

Commit

Permalink
fix(mapping): make mapping work with fallback column name
Browse files Browse the repository at this point in the history
  • Loading branch information
RWOverdijk committed Nov 6, 2016
1 parent 679bc80 commit 714f086
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/Mapping.ts
Expand Up @@ -188,8 +188,15 @@ export class Mapping<T> {


let toUnderscore = entityManager.getConfig().fetch('mapping.defaultNamesToUnderscore'); let toUnderscore = entityManager.getConfig().fetch('mapping.defaultNamesToUnderscore');
let propertyName = toUnderscore ? this.nameToUnderscore(property) : property; 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); this.mapColumn(this.getColumnName(property), property);


Expand Down Expand Up @@ -818,9 +825,18 @@ export class Mapping<T> {
* @returns {Mapping} * @returns {Mapping}
*/ */
public extendField(property: string, additional: Object): this { 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; return this;
} }
Expand Down

0 comments on commit 714f086

Please sign in to comment.