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

Commit 6aab1285 by Daniel Durante

Merge pull request #880 from domasx2/master

tests & bugfixes for DAO-Factory.update and array of values in where clause
2 parents 3c394fdd 82edcdd3
......@@ -656,8 +656,8 @@ module.exports = (function() {
*/
DAOFactory.prototype.update = function(attrValueHash, where, options) {
options = options || {}
options.validate = options.validate || true
options.validate = options.validate === undefined ? true : Boolean(options.validate)
if(this.options.timestamps) {
var attr = Utils._.underscoredIf(this.options.updatedAt, this.options.underscored)
attrValueHash[attr] = Utils.now()
......
......@@ -565,16 +565,19 @@ module.exports = (function() {
if (Array.isArray(value)) {
if (value.length === 0) { value = [null] }
var col = null, coltype = null
// Special conditions for searching within an array column type
var _realKey = key.split('.').pop()
if (!!factory && !!factory.rawAttributes[_realKey]) {
var col = factory.rawAttributes[_realKey]
if ((!!col.type && col.type.match(/\[\]$/) !== null) || (col.toString().match(/\[\]$/) !== null)) {
_value = 'ARRAY[' + value.map(this.escape).join(',') + ']::' + (!!col.type ? col.type : col.toString())
result.push([_key, _value].join(" && "))
col = factory.rawAttributes[_realKey]
coltype = col.type
if(coltype && !(typeof coltype == 'string')) {
coltype = coltype.toString();
}
}
if ( col && ((!!coltype && coltype.match(/\[\]$/) !== null) || (col.toString().match(/\[\]$/) !== null))) {
_value = 'ARRAY[' + value.map(this.escape).join(',') + ']::' + (!!col.type ? col.type : col.toString())
result.push([_key, _value].join(" && "))
} else {
_value = "(" + value.map(this.escape).join(',') + ")"
result.push([_key, _value].join(" IN "))
......
......@@ -1088,6 +1088,27 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
it('should be able to find rows where attribute is in a list of values', function (done) {
this.User.findAll({
where: {
username: ['boo', 'boo2']
}
}).success(function(users){
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();
});
})
it('should be able to find a row using like', function(done) {
this.User.findAll({
where: {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!