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

Filter projections in complex queries #85

Merged
merged 1 commit into from
Mar 23, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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