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

Commit 988f0902 by Mick Hansen

add test for queryInterface.createTable with AI PK

1 parent 04e562a1
......@@ -67,6 +67,10 @@ module.exports = (function() {
if (this.isInsertQuery(data)) {
this.handleInsertQuery(data);
if (!this.callee) {
result = data[this.getInsertIdField()];
}
}
if (this.isSelectQuery()) {
......
......@@ -233,7 +233,7 @@ module.exports = (function() {
}
}
return self.callee;
return self.callee || (rows && rows[0]) || undefined;
} else {
return results;
}
......
......@@ -60,6 +60,10 @@ module.exports = (function() {
// add the inserted row id to the instance
if (self.isInsertQuery(results, metaData)) {
self.handleInsertQuery(results, metaData);
if (!self.callee) {
result = metaData[self.getInsertIdField()];
}
}
if (self.sql.indexOf('sqlite_master') !== -1) {
......
......@@ -450,11 +450,11 @@ module.exports = (function() {
};
QueryInterface.prototype.insert = function(dao, tableName, values, options) {
var sql = this.QueryGenerator.insertQuery(tableName, values, dao.Model.rawAttributes, options);
var sql = this.QueryGenerator.insertQuery(tableName, values, dao && dao.Model.rawAttributes, options);
options.type = 'INSERT';
return this.sequelize.query(sql, dao, options).then(function(result) {
result.isNewRecord = false;
if (dao) result.isNewRecord = false;
return result;
});
};
......
......@@ -149,6 +149,20 @@ describe(Support.getTestDialectTeaser("QueryInterface"), function () {
})
describe('createTable', function () {
it('should create a auto increment primary key', function () {
return this.queryInterface.createTable('TableWithPK', {
table_id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
}
}).bind(this).then(function () {
return this.queryInterface.insert(null, 'TableWithPK', {}, {raw: true, returning: true}).then(function (response) {
expect(response.table_id || (typeof response !== "object" && response)).to.be.ok;
});
});
});
it('should work with enums (1)', function () {
return this.queryInterface.createTable('SomeTable', {
someEnum: DataTypes.ENUM('value1', 'value2', 'value3')
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!