From 96020c7e7e6f8ce771c20c82f47e4f0aeabcb759 Mon Sep 17 00:00:00 2001 From: eugene-frb Date: Thu, 19 Nov 2015 11:10:52 -0800 Subject: [PATCH 1/2] Capture includeHasMany() as a find()'s caller by findCaller option To replace incorrect location of capturing this condition in find() in loopback-connector/lib/sql.js proposed earlier in https://github.com/strongloop/loopback-connector/pull/34. Being set to 'includeHasMany', findCaller option triggers injection of PARTITION BY clause in buildColumnNames() in loopback-connector-mssql/lib/mssql.js only when find() function is called to process include filter with 'has many' relation. --- lib/include.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/include.js b/lib/include.js index a88a2458..19573068 100644 --- a/lib/include.js +++ b/lib/include.js @@ -507,6 +507,7 @@ Inclusion.include = function (objects, include, options, cb) { inq: uniq(sourceIds) }; relation.applyScope(null, filter); + options.findCaller = 'includeHasMany'; relation.modelTo.find(filter, options, targetFetchHandler); /** * Process fetched related objects From ba4600e564f1fa936be8ee05a6fe64430c75daf3 Mon Sep 17 00:00:00 2001 From: eugene-frb Date: Wed, 25 Nov 2015 13:56:59 -0800 Subject: [PATCH 2/2] Explicitly initialize column of partition by clause and pass it in find()'s options argument --- lib/include.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/include.js b/lib/include.js index 19573068..ba77cdf7 100644 --- a/lib/include.js +++ b/lib/include.js @@ -507,7 +507,7 @@ Inclusion.include = function (objects, include, options, cb) { inq: uniq(sourceIds) }; relation.applyScope(null, filter); - options.findCaller = 'includeHasMany'; + options.partitionBy = relation.keyTo; relation.modelTo.find(filter, options, targetFetchHandler); /** * Process fetched related objects