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

Commit 82edcdd3 by Domas Lapinskas

test & fix for searching for rows using an array of primary keys

1 parent 04062312
...@@ -565,13 +565,17 @@ module.exports = (function() { ...@@ -565,13 +565,17 @@ module.exports = (function() {
if (Array.isArray(value)) { if (Array.isArray(value)) {
if (value.length === 0) { value = [null] } if (value.length === 0) { value = [null] }
var col = null; var col = null, coltype = null
// Special conditions for searching within an array column type // Special conditions for searching within an array column type
var _realKey = key.split('.').pop() var _realKey = key.split('.').pop()
if (!!factory && !!factory.rawAttributes[_realKey]) { if (!!factory && !!factory.rawAttributes[_realKey]) {
col = factory.rawAttributes[_realKey] col = factory.rawAttributes[_realKey]
coltype = col.type
if(coltype && !(typeof coltype == 'string')) {
coltype = coltype.toString();
}
} }
if ( col && ((!!col.type && col.type.match(/\[\]$/) !== null) || (col.toString().match(/\[\]$/) !== null))) { if ( col && ((!!coltype && coltype.match(/\[\]$/) !== null) || (col.toString().match(/\[\]$/) !== null))) {
_value = 'ARRAY[' + value.map(this.escape).join(',') + ']::' + (!!col.type ? col.type : col.toString()) _value = 'ARRAY[' + value.map(this.escape).join(',') + ']::' + (!!col.type ? col.type : col.toString())
result.push([_key, _value].join(" && ")) result.push([_key, _value].join(" && "))
} else { } else {
......
...@@ -1064,13 +1064,24 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () { ...@@ -1064,13 +1064,24 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
}) })
}) })
it('should be able to find rows where attribute is in a list of values', function () { it('should be able to find rows where attribute is in a list of values', function (done) {
this.User.findAll({ this.User.findAll({
where: { where: {
username: ['boo', 'boo2'] username: ['boo', 'boo2']
} }
}).success(function(users){ }).success(function(users){
expect(users).to.have.length(2); expect(users).to.have.length(2);
done()
});
})
it('should not break when trying to find rows using an array of primary keys', function (done) {
this.User.findAll({
where: {
id: [1, 2, 3]
}
}).success(function(users){
done();
}); });
}) })
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!