diff --git a/client.js b/client.js index af493b6..70276d6 100644 --- a/client.js +++ b/client.js @@ -54,7 +54,7 @@ function($rootScope, MeteorCollections, $meteorObject) { //console.log(document); if (!array) { - value = new $meteorObject(collection, document); + _.extend(value, document); } if (array) { value[atIndex] = new $meteorObject(collection, document); @@ -62,8 +62,11 @@ function($rootScope, MeteorCollections, $meteorObject) { $rootScope.apply(); }, "changedAt" : function(newDocument, oldDocument, atIndex) { - - value[atIndex] = new $meteorObject(collection, newDocument); + if (array) { + value[atIndex] = new $meteorObject(collection, newDocument); + } else { + _.extend(value, newDocument); + } $rootScope.apply(); }, "removedAt" : function(oldDocument, atIndex) { @@ -79,8 +82,9 @@ function($rootScope, MeteorCollections, $meteorObject) { return value; } Collection.findOne = function(selector, options, callback) { - value = this instanceof Collection ? this : {}; - value = new $meteorObject(collection,collection.find(selector,options).fetch()[0]); + var doc = collection.find(selector, options).fetch()[0]; + if (!doc) doc = {}; + value = new $meteorObject(collection, doc); this.observe(collection.find(selector, options), false); return value; }