Skip to content
This repository has been archived by the owner on Aug 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request #85 from balderdashy/fix-complex-select
Browse files Browse the repository at this point in the history
Filter projections in complex queries
  • Loading branch information
particlebanana committed Mar 23, 2016
2 parents ea36547 + 4ecceff commit b3fb13d
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions sequel/where.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,24 @@ WhereBuilder.prototype.complex = function complex(queryObject, options) {

_.each(selectKeys, function(projection) {
var projectionAlias = _.find(_.values(self.schema), {tableName: projection.table}).tableName;

// Find the projection in the schema and make sure it's a valid key
// that can be selected.
var schema = _.find(self.schema[projection.table]);
if(!schema) {
return;
}

var schemaVal = schema[projection.key];
if(!schemaVal) {
return;
}

// If this is a virtual attribute, it can't be selected
if(_.has(schemaVal, 'collection')) {
return;
}

queryString += utils.escapeName(projectionAlias, self.escapeCharacter) + '.' +
utils.escapeName(projection.key, self.escapeCharacter) + ',';
});
Expand Down Expand Up @@ -326,6 +344,24 @@ WhereBuilder.prototype.complex = function complex(queryObject, options) {
queryString += '(SELECT ';
selectKeys.forEach(function(projection) {
var projectionAlias = _.find(_.values(self.schema), {tableName: projection.table}).tableName;

// Find the projection in the schema and make sure it's a valid key
// that can be selected.
var schema = _.find(self.schema[projection.table]);
if(!schema) {
return;
}

var schemaVal = schema[projection.key];
if(!schemaVal) {
return;
}

// If this is a virtual attribute, it can't be selected
if(_.has(schemaVal, 'collection')) {
return;
}

queryString += utils.escapeName(projectionAlias, self.escapeCharacter) + '.' + utils.escapeName(projection.key, self.escapeCharacter) + ',';
});

Expand Down

0 comments on commit b3fb13d

Please sign in to comment.