use fromDb to deserialize data after save in Memory connector

Changes the after `save` callback in the memory connector to use the
`fromDb` method to deserialize the data passed back to upsert and
updateAttributes methods.
This commit is contained in:
Bryan Clark 2015-06-18 15:18:44 -07:00
parent cf1dee2d64
commit 1066313f3f
2 changed files with 15 additions and 1 deletions

View File

@ -238,6 +238,7 @@ Memory.prototype.updateOrCreate = function (model, data, options, callback) {
};
Memory.prototype.save = function save(model, data, options, callback) {
var self = this;
var id = this.getIdValue(model, data);
var cachedModels = this.collection(model);
var modelData = cachedModels && this.collection(model)[id];
@ -247,7 +248,7 @@ Memory.prototype.save = function save(model, data, options, callback) {
}
this.collection(model)[id] = serialize(data);
this.saveToFile(data, function(err) {
callback(err, data, { isNewInstance: !modelData });
callback(err, self.fromDb(model, data), { isNewInstance: !modelData });
});
};

View File

@ -389,6 +389,19 @@ describe('Memory connector', function() {
});
});
it('should deserialize values after saving in upsert', function(done) {
User.findOne({where: {seq: 1}}, function(err, paul) {
User.updateOrCreate({id: paul.id, name: 'Sir Paul McCartney'},
function(err, sirpaul) {
should.not.exist(err);
sirpaul.birthday.should.be.instanceOf(Date);
sirpaul.order.should.be.instanceOf(Number);
sirpaul.vip.should.be.instanceOf(Boolean);
done();
});
});
});
function seed(done) {
var beatles = [
{