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

Commit f7904548 by Mick Hansen

fix bulkCreate so it sets the returned autoincremented primary key values on the daos

1 parent 5517acd8
......@@ -786,7 +786,14 @@ module.exports = (function() {
})
.error(function(err) {
emitter.emit('error', err)
}).success(function() {
}).success(function(rows) {
rows.forEach(function (row, i) {
Object.keys(daos[i].__factory.primaryKeys).concat('id').forEach(function (primarKey) {
if (row.hasOwnProperty(primarKey)) {
daos[i].setDataValue(primarKey, row[primarKey])
}
})
})
done()
})
}
......
......@@ -37,6 +37,7 @@ module.exports = (function() {
query.on('error', function(err) {
receivedError = true
err.sql = sql
self.emit('sql', sql)
self.emit('error', err, self.callee)
})
......@@ -125,6 +126,7 @@ module.exports = (function() {
})
})
}
this.emit('success', this.send('handleSelectQuery', rows))
}
} else if (this.send('isShowOrDescribeQuery')) {
......@@ -140,9 +142,10 @@ module.exports = (function() {
this.callee[key] = record
}
}
}
this.emit('success', this.callee)
this.emit('success', this.callee)
} else {
this.emit('success', rows)
}
} else if (this.send('isUpdateQuery')) {
if(this.callee !== null) { // may happen for bulk updates
for (var key in rows[0]) {
......
......@@ -894,6 +894,20 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
it('should return instances with primary key values (autoincremented)', function (done) {
var Worker = this.sequelize.define('Worker', {})
Worker.sync().done(function(err) {
Worker.bulkCreate([{}, {}]).done(function (err, workers) {
expect(err).not.to.be.ok
expect(workers).to.be.ok
workers.forEach(function (worker) {
expect(worker.id).to.be.ok
})
done()
})
})
})
describe('enums', function() {
it('correctly restores enum values', function(done) {
var self = this
......
......@@ -106,4 +106,32 @@ it('should support a simple nested hasOne -> hasOne include', function (done) {
})
})
})
it('should support a simple nested hasMany -> belongsTo include', function (done) {
var Task = this.sequelize.define('Task', {})
, User = this.sequelize.define('User', {})
, Project = this.sequelize.define('Project', {})
User.hasMany(Task)
Task.belongsTo(Project)
this.sequelize.sync({force: true}).done(function () {
async.auto({
user: function (callback) {
User.create().done(callback)
},
projects: function (callback) {
Project.bulkCreate([{}, {}]).done(callback)
},
tasks: ['projects', function(callback, results) {
Task.bulkCreate([
{ProjectId: results.projects[0].id},
{ProjectId: results.projects[1].id},
{ProjectId: results.projects[0].id},
{ProjectId: results.projects[1].id}
]).done(callback)
}]
}, done);
});
})
})
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!