Comparing version 0.6.20 to 0.6.21
@@ -222,2 +222,5 @@ !function () { | ||
* prepare the rootresource | ||
* | ||
* @param <Boolean> isSubQuery is this query part of the select statement of another query? | ||
* @param <Boolean> skipSelect ? | ||
*/ | ||
@@ -271,3 +274,14 @@ , prepare: function(skipSelect, isSubQuery) { | ||
resource.getChildren().forEach(function(childResource) { | ||
// we nede to apply our filter to all parent queries | ||
// execpt for the root resource (thats happened already) | ||
// all subselects need to be filtered in the same way as | ||
// the parent was filtered | ||
this.applyFiltersToParents(this.getParent(), this); | ||
// select | ||
childResource.prepareRootQuery(); | ||
// go up the tree | ||
this._prepareChildrenForRootResource(childResource); | ||
@@ -297,6 +311,3 @@ }.bind(this)); | ||
// filter all subselects | ||
this.applyFiltersToParents(this.getParent(), this); | ||
if (this.isSelected() && !this.selectApplied()) { | ||
@@ -348,8 +359,8 @@ parent = this.getParent(); | ||
*/ | ||
, applyFiltersToParents: function(resource, sourceResource, joins, childResource) { | ||
//if (!childResource) log.warn('no childResource'); | ||
if (!childResource) childResource = sourceResource; | ||
, applyFiltersToParents: function(currentTargetResource, sourceResource, joins, lastTargetResource) { | ||
if (!lastTargetResource) lastTargetResource = sourceResource; | ||
if (sourceResource.hasFiltersForTheRootResource() && resource && !resource.isRootResource() && !sourceResource.parentsFiltered) { | ||
// has filter, current target is not root, filters not yet applied | ||
if (sourceResource.hasFiltersForTheRootResource() && currentTargetResource && !currentTargetResource.isRootResource() && !sourceResource.parentsFiltered) { | ||
var name = sourceResource.query.from | ||
@@ -359,13 +370,14 @@ , targetFilter; | ||
if (debug) log.debug('applying filters on %s to the parent %s ...', sourceResource.name, resource.name); | ||
if (debug) log.debug('applying sub-join from %s to %s ...'.cyan, sourceResource.name, resource.name); | ||
if (debug) log.debug('applying filters on %s to the parent %s ...', sourceResource.name, currentTargetResource.name); | ||
if (debug) log.debug('applying sub-join from %s to %s ...'.cyan, sourceResource.name, currentTargetResource.name); | ||
// if there are no joins, take a revered copy of mine | ||
if (!joins) joins = sourceResource.joins.slice().reverse(); | ||
// make sure there is an object to write to | ||
if (!resource.query.filter[name]) resource.query.filter[name] = {}; | ||
if (!currentTargetResource.query.filter[name]) currentTargetResource.query.filter[name] = {}; | ||
// normal filters | ||
// copy my filters to the parent resource | ||
if (sourceResource.filters && Object.keys(sourceResource.filters).length) { | ||
targetFilter = resource.query.filter[name]; | ||
targetFilter = currentTargetResource.query.filter[name]; | ||
@@ -377,17 +389,18 @@ Object.keys(sourceResource.filters).forEach(function(key){ | ||
// take the joins, apply them to the parent | ||
joins.forEach(function(joinStatement, index) { | ||
resource.query.join.push(joinStatement.reverseFormat()); | ||
currentTargetResource.query.join.push(joinStatement.reverseFormat()); | ||
}.bind(this)); | ||
// we should not join any table twice | ||
if (sourceResource.subJoinApplied || resource.subJoinApplied) { | ||
this.applyFiltersToParents(resource.getParent(), sourceResource, joins, resource); | ||
// we should not join any table twice, check if we joined this pair already | ||
if (currentTargetResource.subJoinApplied && lastTargetResource.subJoinApplied) { | ||
this.applyFiltersToParents(currentTargetResource.getParent(), sourceResource, joins, currentTargetResource); | ||
} | ||
else { | ||
sourceResource.subJoinApplied = true; | ||
resource.subJoinApplied = true; | ||
this.applyFiltersToParents(resource.getParent(), sourceResource, resource.joins.slice().reverse().concat(joins), resource); | ||
lastTargetResource.subJoinApplied = true; | ||
currentTargetResource.subJoinApplied = true; | ||
this.applyFiltersToParents(currentTargetResource.getParent(), sourceResource, currentTargetResource.joins.slice().reverse().concat(joins), currentTargetResource); | ||
} | ||
// tage the source, makes sure its not added twice | ||
sourceResource.parentsFiltered = true; | ||
@@ -394,0 +407,0 @@ } |
{ | ||
"name" : "ee-orm" | ||
, "description" : "An easy to use ORM for node.js. Supports eager loading, complex queries, joins, transactions, complex database clusters & connection pooling." | ||
, "version" : "0.6.20" | ||
, "version" : "0.6.21" | ||
, "homepage" : "https://github.com/eventEmitter/ee-orm" | ||
@@ -6,0 +6,0 @@ , "author" : "Michael van der Weg <michael@eventemitter.com> (http://eventemitter.com/)" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
251399
4784