backbone-db-mongodb
Advanced tools
Comparing version 0.2.8 to 0.2.9
19
index.js
@@ -76,2 +76,20 @@ var _ = require('lodash'), | ||
options = options || {}; | ||
if (!model.model && !options.where) { | ||
debug('fetch model'); | ||
var indexedKeys = _.pluck(model.indexes, 'property'); | ||
var objectKeys = Object.keys(model.attributes); | ||
var searchAttrs = {}; | ||
_.each(objectKeys, function(attr) { | ||
if(indexedKeys.indexOf(attr) > -1) { | ||
searchAttrs[attr] = model.get(attr); | ||
} | ||
}); | ||
if (!Object.keys(searchAttrs).length) { | ||
var err = new Error('Cannot fetch model with given attributes'); | ||
return callback(err); | ||
} | ||
options.where = searchAttrs; | ||
} | ||
var query = options.where || {}; | ||
@@ -104,2 +122,3 @@ var offset = options.offset || 0; | ||
res = self._filter(res, model); | ||
if(!model.model) return callback(err, res && res.length && res[0]); | ||
callback(err, res); | ||
@@ -106,0 +125,0 @@ }); |
{ | ||
"name": "backbone-db-mongodb", | ||
"version": "0.2.8", | ||
"version": "0.2.9", | ||
"description": "MongoDB driver for Backbone.Db", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
122714
779