Allow queries to filter fields
This commit is contained in:
parent
d4ca20c01a
commit
22db369fb8
17
lib/dao.js
17
lib/dao.js
|
@ -294,6 +294,11 @@ DataAccessObject.findById.http = [
|
||||||
{verb: 'get', path: '/:id'}
|
{verb: 'get', path: '/:id'}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// alias function for backwards compat.
|
||||||
|
DataAccessObject.all = function () {
|
||||||
|
DataAccessObject.find.apply(this, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find all instances of Model, matched by query
|
* Find all instances of Model, matched by query
|
||||||
* make sure you have marked as `index: true` fields for filter or sort
|
* make sure you have marked as `index: true` fields for filter or sort
|
||||||
|
@ -312,7 +317,6 @@ DataAccessObject.findById.http = [
|
||||||
* - Array of instances
|
* - Array of instances
|
||||||
*/
|
*/
|
||||||
|
|
||||||
DataAccessObject.all =
|
|
||||||
DataAccessObject.find = function find(params, cb) {
|
DataAccessObject.find = function find(params, cb) {
|
||||||
if (stillConnecting(this.schema, this, arguments)) return;
|
if (stillConnecting(this.schema, this, arguments)) return;
|
||||||
|
|
||||||
|
@ -322,8 +326,8 @@ DataAccessObject.find = function find(params, cb) {
|
||||||
}
|
}
|
||||||
var constr = this;
|
var constr = this;
|
||||||
|
|
||||||
|
params = params || {};
|
||||||
var fields = params && params.fields;
|
var fields = params.fields;
|
||||||
var near = params && geo.nearFilter(params.where);
|
var near = params && geo.nearFilter(params.where);
|
||||||
var supportsGeo = !!this.schema.adapter.buildNearFilter;
|
var supportsGeo = !!this.schema.adapter.buildNearFilter;
|
||||||
|
|
||||||
|
@ -373,7 +377,9 @@ DataAccessObject.find = function find(params, cb) {
|
||||||
if (data && data.forEach) {
|
if (data && data.forEach) {
|
||||||
data.forEach(function (d, i) {
|
data.forEach(function (d, i) {
|
||||||
var obj = new constr;
|
var obj = new constr;
|
||||||
obj._initProperties(d, false);
|
|
||||||
|
obj._initProperties(d, false, params.fields);
|
||||||
|
|
||||||
if (params && params.include && params.collect) {
|
if (params && params.include && params.collect) {
|
||||||
data[i] = obj.__cachedRelations[params.collect];
|
data[i] = obj.__cachedRelations[params.collect];
|
||||||
} else {
|
} else {
|
||||||
|
@ -398,8 +404,7 @@ DataAccessObject.find = function find(params, cb) {
|
||||||
DataAccessObject.find.accepts = {arg: 'filter', type: 'object'};
|
DataAccessObject.find.accepts = {arg: 'filter', type: 'object'};
|
||||||
DataAccessObject.find.shared = true;
|
DataAccessObject.find.shared = true;
|
||||||
DataAccessObject.find.http = [
|
DataAccessObject.find.http = [
|
||||||
{verb: 'get', path: '/'},
|
{verb: 'get', path: '/'}
|
||||||
{verb: 'get', path: '/all'}
|
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue