Merge pull request #1739 from strongloop/fix/hooks-with-near-queries
Fix implementation of Operation Hooks for "near" (geo) queries
This commit is contained in:
commit
413f31631e
29
lib/dao.js
29
lib/dao.js
|
@ -1535,7 +1535,7 @@ DataAccessObject.find = function find(query, options, cb) {
|
|||
|
||||
this.applyScope(query);
|
||||
|
||||
const near = query && geo.nearFilter(query.where);
|
||||
let near = query && geo.nearFilter(query.where);
|
||||
const supportsGeo = !!connector.buildNearFilter;
|
||||
let geoQueryObject;
|
||||
|
||||
|
@ -1569,7 +1569,8 @@ DataAccessObject.find = function find(query, options, cb) {
|
|||
return cb.promise;
|
||||
}
|
||||
}
|
||||
function geoCallbackWithoutNotify(err, data) {
|
||||
|
||||
function geoCallback(err, data) {
|
||||
const memory = new Memory();
|
||||
const modelName = self.modelName;
|
||||
|
||||
|
@ -1588,37 +1589,15 @@ DataAccessObject.find = function find(query, options, cb) {
|
|||
});
|
||||
});
|
||||
|
||||
// FIXME: apply "includes" and other transforms - see allCb below
|
||||
memory.all(modelName, geoQueryObject, options, allCb);
|
||||
} else {
|
||||
cb(null, []);
|
||||
}
|
||||
}
|
||||
|
||||
function geoCallbackWithNotify(err, data) {
|
||||
if (err) return cb(err);
|
||||
|
||||
async.map(data, function(item, next) {
|
||||
const context = {
|
||||
Model: self,
|
||||
data: item,
|
||||
isNewInstance: false,
|
||||
hookState: hookState,
|
||||
options: options,
|
||||
};
|
||||
|
||||
self.notifyObserversOf('loaded', context, function(err) {
|
||||
if (err) return next(err);
|
||||
next(null, context.data);
|
||||
});
|
||||
}, function(err, results) {
|
||||
if (err) return cb(err);
|
||||
geoCallbackWithoutNotify(null, results);
|
||||
});
|
||||
}
|
||||
function queryGeo(query) {
|
||||
geoQueryObject = query;
|
||||
const geoCallback = options.notify === false ? geoCallbackWithoutNotify : geoCallbackWithNotify;
|
||||
near = query && geo.nearFilter(query.where);
|
||||
invokeConnectorMethod(connector, 'all', self, [{}], options, geoCallback);
|
||||
}
|
||||
|
||||
|
|
|
@ -917,6 +917,9 @@ describe('Unoptimized connector', function() {
|
|||
ds.connector.findOrCreate = false;
|
||||
ds.connector.upsertWithWhere = false;
|
||||
|
||||
// disable native location queries
|
||||
ds.connector.buildNearFilter = false;
|
||||
|
||||
require('./persistence-hooks.suite')(ds, should, {
|
||||
replaceOrCreateReportsNewInstance: true,
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue