diff --git a/lib/dialects/postgres/query.js b/lib/dialects/postgres/query.js index 92f0685f0da8..13f421bc44da 100644 --- a/lib/dialects/postgres/query.js +++ b/lib/dialects/postgres/query.js @@ -139,7 +139,7 @@ module.exports = (function() { if (!!this.callee.daoFactory && !!this.callee.daoFactory.rawAttributes && !!this.callee.daoFactory.rawAttributes[key] && !!this.callee.daoFactory.rawAttributes[key].type && !!this.callee.daoFactory.rawAttributes[key].type.type && this.callee.daoFactory.rawAttributes[key].type.type === DataTypes.HSTORE.type) { record = hstore.parse(record) } - this.callee[key] = record + this.callee.dataValues[key] = record } } } @@ -152,7 +152,7 @@ module.exports = (function() { if (!!this.callee.daoFactory && !!this.callee.daoFactory.rawAttributes && !!this.callee.daoFactory.rawAttributes[key] && !!this.callee.daoFactory.rawAttributes[key].type && !!this.callee.daoFactory.rawAttributes[key].type.type && this.callee.daoFactory.rawAttributes[key].type.type === DataTypes.HSTORE.type) { record = hstore.parse(record) } - this.callee[key] = record + this.callee.dataValues[key] = record } } } diff --git a/test/dao/values.test.js b/test/dao/values.test.js index 17937238f79c..dc45fff3cf85 100644 --- a/test/dao/values.test.js +++ b/test/dao/values.test.js @@ -193,6 +193,40 @@ describe(Support.getTestDialectTeaser("DAO"), function () { }) expect(product.toJSON()).to.deep.equal({withTaxes: 1250, price: 1000, id: null}) }) + + it('should work with save', function (done) { + var Contact = this.sequelize.define('Contact', { + first: { type: Sequelize.STRING }, + last: { type: Sequelize.STRING }, + tags: { + type: Sequelize.STRING, + get: function(field) { + var val = this.getDataValue(field); + return JSON.parse(val); + }, + set: function(val, field) { + this.setDataValue(field, JSON.stringify(val)); + } + } + }); + + this.sequelize.sync().done(function () { + var contact = Contact.build({ + first: 'My', + last: 'Name', + tags: ['yes','no'] + }); + expect(contact.get('tags')).to.deep.equal(['yes', 'no']) + + contact.save().done(function(err, me) { + expect(err).not.to.be.ok + var idToTest = me.id; + + expect(me.get('tags')).to.deep.equal(['yes', 'no']) + done(); + }); + }); + }) }) describe('changed', function () {