Skip to content

Commit

Permalink
Merge pull request #1239 from mickhansen/fix-issue-1234
Browse files Browse the repository at this point in the history
Fix for #1234 - Postgres query should set on .dataValues instead of object
  • Loading branch information
mickhansen committed Jan 11, 2014
2 parents 069bec8 + 9c53f5a commit 6c9ade1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/dialects/postgres/query.js
Expand Up @@ -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
}
}
}
Expand All @@ -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
}
}
}
Expand Down
34 changes: 34 additions & 0 deletions test/dao/values.test.js
Expand Up @@ -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 () {
Expand Down

0 comments on commit 6c9ade1

Please sign in to comment.