Skip to content

Commit 2e7a86d

Browse files
committed
Fix serialization of arrays of string in update
1 parent 3ca9536 commit 2e7a86d

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

lib/postgresql.js

+4
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,10 @@ PostgreSQL.prototype.toColumnValue = function(prop, val, isWhereClause) {
766766
});
767767
}
768768

769+
if (prop.type instanceof Array && prop.type[0] === String) {
770+
return JSON.stringify(val);
771+
}
772+
769773
return val;
770774
};
771775

test/postgresql.test.js

+25
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ describe('postgresql connector', function() {
6464
loc: 'GeoPoint',
6565
created: Date,
6666
approved: Boolean,
67+
tags: {
68+
type: ['string'],
69+
},
6770
});
6871
created = new Date();
6972
});
@@ -201,6 +204,28 @@ describe('postgresql connector', function() {
201204
});
202205
});
203206

207+
it('should support updating arrays of string types', function(done) {
208+
let postId;
209+
Post.create({title: 'Updating Arrays', content: 'Content', tags: ['AA', 'AB']})
210+
.then((post)=> {
211+
postId = post.id;
212+
post.should.have.property('tags');
213+
post.tags[1].should.eql('AB');
214+
return Post.updateAll({where: {id: postId}}, {tags: ['AA', 'AC']});
215+
})
216+
.then((wooot)=> {
217+
return Post.findOne({where: {id: postId}});
218+
})
219+
.then((post)=> {
220+
post.should.have.property('tags');
221+
post.tags[1].should.eql('AC');
222+
done();
223+
})
224+
.catch((error) => {
225+
done(error);
226+
});
227+
});
228+
204229
it('should support boolean types with false value', function(done) {
205230
Post.create(
206231
{title: 'T2', content: 'C2', approved: false, created: created},

0 commit comments

Comments
 (0)