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

Commit fee30324 by Mick Hansen

Prefix options.attributes in find/findall if need by (includes)

1 parent 1219b188
......@@ -367,12 +367,19 @@ module.exports = (function() {
options = options || {}
options.table = table = Array.isArray(tableName) ? tableName.map(function(t) { return this.quoteIdentifiers(t) }.bind(this)).join(", ") : this.quoteIdentifiers(tableName)
options.attributes = options.attributes && options.attributes.map(function(attr){
if(Array.isArray(attr) && attr.length == 2) {
return [attr[0], this.quoteIdentifier(attr[1])].join(' as ')
attr = [attr[0], this.quoteIdentifier(attr[1])].join(' as ')
} else {
return attr.indexOf(Utils.TICK_CHAR) < 0 && attr.indexOf('"') < 0 ? this.quoteIdentifiers(attr) : attr
attr = attr.indexOf(Utils.TICK_CHAR) < 0 && attr.indexOf('"') < 0 ? this.quoteIdentifiers(attr) : attr
}
if (options.include && attr.indexOf('.') === -1) {
attr = this.quoteIdentifier(options.table) + '.' + attr
}
return attr
}.bind(this)).join(", ")
options.attributes = options.attributes || '*'
......
......@@ -454,6 +454,30 @@ describe(Support.getTestDialectTeaser("Include"), function () {
})
})
})
it('should support specifying attributes', function (done) {
var Project = this.sequelize.define('Project', {
title: Sequelize.STRING
})
var Task = this.sequelize.define('Task', {
title: Sequelize.STRING,
description: Sequelize.TEXT
})
Project.hasMany(Task)
Task.belongsTo(Project)
this.sequelize.sync().done(function() {
Task.create({title: 'FooBar'}).done(function (err) {
Task.findAll({attributes: ['title'], include: [Project]}).done(function(err, tasks) {
expect(err).not.to.be.ok
expect(tasks[0].title).to.equal('FooBar')
done()
})
})
})
})
})
describe('findAll', function () {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!