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

Commit a1a31073 by Jan Aagaard Meier

Fix for newlines in hstore. Closes #3383. Also fixes an unrelated include test

1 parent f93294de
# Next
- [BUG] Fix for newlines in hstore [#3383](https://github.com/sequelize/sequelize/issues/3383)
# 2.0.5 # 2.0.5
- [FEATURE] Highly experimental support for nested creation [#3386](https://github.com/sequelize/sequelize/pull/3386) - [FEATURE] Highly experimental support for nested creation [#3386](https://github.com/sequelize/sequelize/pull/3386)
......
...@@ -18,9 +18,15 @@ parseDialectSpecificFields = { ...@@ -18,9 +18,15 @@ parseDialectSpecificFields = {
hstore: function (value, options) { hstore: function (value, options) {
if (value === null) return null; if (value === null) return null;
// hstore does not require you to escape newlines, but JSON.parse does!
return DataTypes.ARRAY.is(options.dataType, DataTypes.HSTORE) ? return DataTypes.ARRAY.is(options.dataType, DataTypes.HSTORE) ?
Utils._.map( Utils._.map(
JSON.parse('[' + value.substring(1, value.length - 1) + ']'), function (v) { JSON.parse('[' +
value.substring(1, value.length - 1)
.replace('\n', '\\n')
.replace('\t', '\\t')
.replace('\r', '\\r') +
']'), function (v) {
return hstore.parse(v); return hstore.parse(v);
}) : hstore.parse(value); }) : hstore.parse(value);
}, },
......
...@@ -540,13 +540,13 @@ if (dialect.match(/^postgres/)) { ...@@ -540,13 +540,13 @@ if (dialect.match(/^postgres/)) {
return this.User.create({ return this.User.create({
username: 'bob', username: 'bob',
email: ['myemail@email.com'], email: ['myemail@email.com'],
phones: [{ number: '123456789', type: 'mobile' }, { number: '987654321', type: 'landline' }, { number: '8675309', type: "Jenny's"}, {number: '5555554321', type: '"home"' }] phones: [{ number: '123456789', type: 'mobile' }, { number: '987654321', type: 'landline' }, { number: '8675309', type: "Jenny's"}, {number: '5555554321', type: '"home\n"' }]
}).then(function() { }).then(function() {
return User.find(1).then(function(user) { return User.find(1).then(function(user) {
expect(user.phones.length).to.equal(4); expect(user.phones.length).to.equal(4);
expect(user.phones[1].number).to.equal('987654321'); expect(user.phones[1].number).to.equal('987654321');
expect(user.phones[2].type).to.equal("Jenny's"); expect(user.phones[2].type).to.equal("Jenny's");
expect(user.phones[3].type).to.equal('"home"'); expect(user.phones[3].type).to.equal('"home\n"');
}); });
}); });
}); });
......
...@@ -24,9 +24,9 @@ describe(Support.getTestDialectTeaser('Include'), function() { ...@@ -24,9 +24,9 @@ describe(Support.getTestDialectTeaser('Include'), function() {
C = this.sequelize.define('C', { name: DataTypes.STRING(40) }, { paranoid: true }); C = this.sequelize.define('C', { name: DataTypes.STRING(40) }, { paranoid: true });
// Associate them // Associate them
User.hasMany(SomeConnection, { foreignKey: 'u' }); User.hasMany(SomeConnection, { foreignKey: 'u', constraints: false });
SomeConnection.belongsTo(User, { foreignKey: 'u' }); SomeConnection.belongsTo(User, { foreignKey: 'u', constraints: false });
SomeConnection.belongsTo(A, { foreignKey: 'fk', constraints: false }); SomeConnection.belongsTo(A, { foreignKey: 'fk', constraints: false });
SomeConnection.belongsTo(B, { foreignKey: 'fk', constraints: false }); SomeConnection.belongsTo(B, { foreignKey: 'fk', constraints: false });
SomeConnection.belongsTo(C, { foreignKey: 'fk', constraints: false }); SomeConnection.belongsTo(C, { foreignKey: 'fk', constraints: false });
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!