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

Commit 9a219699 by Mick Hansen

Merge pull request #1193 from mickhansen/include-attributes-fix

Prefix options.attributes in find/findall if need by (fixes #1190)
2 parents 1219b188 fee30324
...@@ -367,12 +367,19 @@ module.exports = (function() { ...@@ -367,12 +367,19 @@ module.exports = (function() {
options = options || {} options = options || {}
options.table = table = Array.isArray(tableName) ? tableName.map(function(t) { return this.quoteIdentifiers(t) }.bind(this)).join(", ") : this.quoteIdentifiers(tableName) 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){ options.attributes = options.attributes && options.attributes.map(function(attr){
if(Array.isArray(attr) && attr.length == 2) { 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 { } 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(", ") }.bind(this)).join(", ")
options.attributes = options.attributes || '*' options.attributes = options.attributes || '*'
......
...@@ -454,6 +454,30 @@ describe(Support.getTestDialectTeaser("Include"), function () { ...@@ -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 () { describe('findAll', function () {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!