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

You need to sign in or sign up before continuing.
Commit 04062312 by Domas Lapinskas

fix searching for rows where attribute is in array of values, test

1 parent 1b222915
...@@ -565,16 +565,15 @@ module.exports = (function() { ...@@ -565,16 +565,15 @@ 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;
// 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]) {
var col = factory.rawAttributes[_realKey] col = factory.rawAttributes[_realKey]
}
if ((!!col.type && col.type.match(/\[\]$/) !== null) || (col.toString().match(/\[\]$/) !== null)) { if ( col && ((!!col.type && col.type.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 {
_value = "(" + value.map(this.escape).join(',') + ")" _value = "(" + value.map(this.escape).join(',') + ")"
result.push([_key, _value].join(" IN ")) result.push([_key, _value].join(" IN "))
......
...@@ -1064,6 +1064,16 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () { ...@@ -1064,6 +1064,16 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
}) })
}) })
it('should be able to find rows where attribute is in a list of values', function () {
this.User.findAll({
where: {
username: ['boo', 'boo2']
}
}).success(function(users){
expect(users).to.have.length(2);
});
})
it('should be able to find a row using like', function(done) { it('should be able to find a row using like', function(done) {
this.User.findAll({ this.User.findAll({
where: { where: {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!