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:
parent
cf1dee2d64
commit
1066313f3f
|
@ -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 });
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -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 = [
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue