Permalink
Browse files

fix(QueryBuilder): Use actual PK, and also only once

  • Loading branch information...
RWOverdijk committed Oct 14, 2016
1 parent 617a5ac commit 7eeb25ae78db00c625562c0d23750d03338cdb00
Showing with 10 additions and 4 deletions.
  1. +10 −4 src/QueryBuilder.ts
@@ -36,6 +36,11 @@ export class QueryBuilder<T> {
*/
private selects: Array<any> = [];
/**
* @type {{}]
*/
private appliedPrimaryKeys: {[key: string]: string};
/**
* @type {Array}
*/
@@ -388,7 +393,7 @@ export class QueryBuilder<T> {
propertyAlias = `${alias}.${propertyAlias}`;
}
let aliasRecipe = this.hydrator.getRecipe(alias);
let aliasRecipe;
let selectAliases = [];
let hydrateColumns = {};
@@ -398,11 +403,12 @@ export class QueryBuilder<T> {
let column = this.criteria.mapToColumn(propertyAlias);
hydrateColumns[column] = property;
alias = parts[0];
aliasRecipe = this.hydrator.getRecipe(alias);
let primaryKeyAlias = `${aliasRecipe.primaryKey.alias} as ${aliasRecipe.primaryKey.alias}`;
if (!this.appliedPrimaryKeys[alias]) {
this.appliedPrimaryKeys[alias] = `${aliasRecipe.primaryKey.alias} as ${aliasRecipe.primaryKey.alias}`;
if (selectAliases.indexOf(primaryKeyAlias) === -1) {
selectAliases.push(primaryKeyAlias);
selectAliases.push(this.appliedPrimaryKeys[alias]);
}
selectAliases.push(`${column} as ${column}`);

0 comments on commit 7eeb25a

Please sign in to comment.