mirror of
https://github.com/zhigang1992/deployd.git
synced 2026-05-13 04:00:35 +08:00
fixed incorrect query for updates
This commit is contained in:
@@ -351,6 +351,8 @@ Store.prototype.update = function (query, object, fn) {
|
||||
if(typeof query != 'object') throw new Error('update requires a query object or string id');
|
||||
if(query.id) store.identify(query);
|
||||
|
||||
stripFields(query);
|
||||
|
||||
collection(this, function (err, col) {
|
||||
col.update(query, object, function(err) {
|
||||
store.identify(query);
|
||||
|
||||
@@ -385,10 +385,6 @@ Collection.prototype.save = function (session, item, query, client, fn) {
|
||||
collection.execListener('Validate', session, query, item, client, function (err, item) {
|
||||
if(err) return fn(err);
|
||||
|
||||
var errors = collection.validate(item, !query.id);
|
||||
|
||||
if(errors) return fn({errors: errors});
|
||||
|
||||
if(query.id) {
|
||||
// is PUT
|
||||
store.first({id: query.id, $fields: query.$fields}, function(err, obj) {
|
||||
@@ -397,6 +393,10 @@ Collection.prototype.save = function (session, item, query, client, fn) {
|
||||
obj[key] = item[key];
|
||||
});
|
||||
|
||||
var errors = collection.validate(item);
|
||||
|
||||
if(errors) return fn({errors: errors});
|
||||
|
||||
collection.execListener('Put', session, query, item, client, function (err, item) {
|
||||
if(err) {
|
||||
err.message = 'Error while executing PUT event: ' + err.message;
|
||||
@@ -413,6 +413,10 @@ Collection.prototype.save = function (session, item, query, client, fn) {
|
||||
});
|
||||
} else {
|
||||
// is POST
|
||||
var errors = collection.validate(item, true);
|
||||
|
||||
if(errors) return fn({errors: errors});
|
||||
|
||||
// generate id before event listener
|
||||
item.id = store.createUniqueIdentifier();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user