Merge pull request #1108 from strongloop/fix_geo_2.x
Fix the bug when near filter is used
This commit is contained in:
commit
8caf4c8327
12
lib/dao.js
12
lib/dao.js
|
@ -1798,11 +1798,7 @@ DataAccessObject.find = function find(query, options, cb) {
|
||||||
var near = query && geo.nearFilter(query.where);
|
var near = query && geo.nearFilter(query.where);
|
||||||
var supportsGeo = !!connector.buildNearFilter;
|
var supportsGeo = !!connector.buildNearFilter;
|
||||||
|
|
||||||
if (near) {
|
if (query.where && near && !supportsGeo) {
|
||||||
if (supportsGeo) {
|
|
||||||
// convert it
|
|
||||||
connector.buildNearFilter(query, near);
|
|
||||||
} else if (query.where) {
|
|
||||||
// do in memory query
|
// do in memory query
|
||||||
// using all documents
|
// using all documents
|
||||||
// TODO [fabien] use default scope here?
|
// TODO [fabien] use default scope here?
|
||||||
|
@ -1825,6 +1821,7 @@ DataAccessObject.find = function find(query, options, cb) {
|
||||||
queryGeo(ctx.query);
|
queryGeo(ctx.query);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function queryGeo(query) {
|
function queryGeo(query) {
|
||||||
function geoCallback(err, data) {
|
function geoCallback(err, data) {
|
||||||
var memory = new Memory();
|
var memory = new Memory();
|
||||||
|
@ -1860,7 +1857,9 @@ DataAccessObject.find = function find(query, options, cb) {
|
||||||
// already handled
|
// already handled
|
||||||
return cb.promise;
|
return cb.promise;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
if (near && supportsGeo) {
|
||||||
|
connector.buildNearFilter(query, near);
|
||||||
}
|
}
|
||||||
|
|
||||||
var allCb = function(err, data) {
|
var allCb = function(err, data) {
|
||||||
|
@ -1966,6 +1965,7 @@ DataAccessObject.find = function find(query, options, cb) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return cb.promise;
|
return cb.promise;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function isDefined(value) {
|
function isDefined(value) {
|
||||||
|
|
|
@ -86,6 +86,19 @@ module.exports = function(dataSource, should, connectorCapabilities) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('triggers correct hooks when near filter is used', function(done) {
|
||||||
|
monitorHookExecution();
|
||||||
|
var query = { where:
|
||||||
|
{ location: { near: '10,20', maxDistance: '10', unit: 'meters' }},
|
||||||
|
};
|
||||||
|
|
||||||
|
TestModel.find(query, function(err, list) {
|
||||||
|
if (err) return done(err);
|
||||||
|
hookMonitor.names.should.eql(['access']);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should not trigger hooks, if notify is false', function(done) {
|
it('should not trigger hooks, if notify is false', function(done) {
|
||||||
monitorHookExecution();
|
monitorHookExecution();
|
||||||
TestModel.find(
|
TestModel.find(
|
||||||
|
|
Loading…
Reference in New Issue