Permalink
Browse files

fix(QueryBuilder): Accept fields without name (PK)

  • Loading branch information...
RWOverdijk committed Oct 8, 2016
1 parent c872c2f commit 834a51b33350202f01cd5ca72ac38644bbfe4bc1
Showing with 12 additions and 3 deletions.
  1. +12 −3 src/QueryBuilder.ts
@@ -407,12 +407,21 @@ export class QueryBuilder<T> {
selectAliases.push(`${column} as ${column}`);
} else {
let fields = this.mappings[propertyAlias].getFields();
alias = propertyAlias;
let mapping = this.mappings[propertyAlias];
let fields = mapping.getFields();
alias = propertyAlias;
Object.getOwnPropertyNames(fields).forEach(field => {
if (!fields[field].relationship) {
let fieldAlias = (propertyAlias ? propertyAlias + '.' : '') + fields[field].name;
let fieldName = fields[field].name || (fields[field].primary ? 'id' : null);
if (!fieldName) {
throw new Error(
`Trying to query for field without a name for '${mapping.getEntityName()}.${field}'.`
);
}
let fieldAlias = (propertyAlias ? propertyAlias + '.' : '') + fieldName;
hydrateColumns[fieldAlias] = field;
selectAliases.push(`${fieldAlias} as ${fieldAlias}`);

0 comments on commit 834a51b

Please sign in to comment.