diff --git a/lib/models/change.js b/lib/models/change.js index bdb3c707..60a6042e 100644 --- a/lib/models/change.js +++ b/lib/models/change.js @@ -172,15 +172,19 @@ Change.prototype.rectify = function(cb) { async.parallel(tasks, function(err) { if(err) return cb(err); - change.save(cb); + if(change.prev === Change.UNKNOWN) { + // this occurs when a record of a change doesn't exist + // and its current revision is null (not found) + change.remove(cb); + } else { + change.save(cb); + } }); function updateRevision(cb) { // get the current revision change.currentRevision(function(err, rev) { if(err) return Change.handleError(err, cb); - change.debug('updating revision ('+ rev +')'); - // deleted if(rev) { // avoid setting rev and prev to the same value if(currentRev !== rev) { @@ -196,10 +200,9 @@ Change.prototype.rectify = function(cb) { } else if(!change.prev) { change.debug('ERROR - could not determing prev'); change.prev = Change.UNKNOWN; - return cb(new Error('could not determine the previous rev for ' - + change.modelId)); } } + change.debug('updated revision (was ' + currentRev + ')'); cb(); }); } @@ -493,8 +496,9 @@ Change.prototype.getModel = function(callback) { * * **Note: call `conflict.fetch()` to get the `target` and `source` models. * - * @param {*} sourceModelId - * @param {*} targetModelId + * @param {*} modelId + * @param {DataModel} SourceModel + * @param {DataModel} TargetModel * @property {ModelClass} source The source model instance * @property {ModelClass} target The target model instance */ @@ -570,9 +574,9 @@ Conflict.prototype.changes = function(cb) { ], done); function getSourceChange(cb) { - conflict.SourceChange.findOne({ - modelId: conflict.sourceModelId - }, function(err, change) { + conflict.SourceChange.findOne({where: { + modelId: conflict.modelId + }}, function(err, change) { if(err) return cb(err); sourceChange = change; cb(); @@ -580,9 +584,9 @@ Conflict.prototype.changes = function(cb) { } function getTargetChange(cb) { - conflict.TargetChange.findOne({ - modelId: conflict.targetModelId - }, function(err, change) { + conflict.TargetChange.findOne({where: { + modelId: conflict.modelId + }}, function(err, change) { if(err) return cb(err); targetChange = change; cb(); diff --git a/lib/models/data-model.js b/lib/models/data-model.js index 5661a790..6b5bf5fb 100644 --- a/lib/models/data-model.js +++ b/lib/models/data-model.js @@ -767,7 +767,8 @@ DataModel.createUpdates = function(deltas, cb) { if(err) return cb(err); if(!inst) { console.error('missing data for change:', change); - return callback(); + return cb && cb(new Error('missing data for change: ' + + change.modelId)); } if(inst.toObject) { update.data = inst.toObject();