不要怂,就是干,撸起袖子干!

Commit 6c9ade1b by Mick Hansen

Merge pull request #1239 from mickhansen/fix-issue-1234

Fix for #1234 - Postgres query should set on .dataValues instead of object
2 parents 069bec8c 9c53f5a7
...@@ -139,7 +139,7 @@ module.exports = (function() { ...@@ -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) { 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) record = hstore.parse(record)
} }
this.callee[key] = record this.callee.dataValues[key] = record
} }
} }
} }
...@@ -152,7 +152,7 @@ module.exports = (function() { ...@@ -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) { 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) record = hstore.parse(record)
} }
this.callee[key] = record this.callee.dataValues[key] = record
} }
} }
} }
......
...@@ -193,6 +193,40 @@ describe(Support.getTestDialectTeaser("DAO"), function () { ...@@ -193,6 +193,40 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
}) })
expect(product.toJSON()).to.deep.equal({withTaxes: 1250, price: 1000, id: null}) 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 () { describe('changed', function () {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!