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

Commit 844ffeb8 by sevastos

Allow the omittion of values on autoincremental columns. Closes #673

1 parent 0d7f3bcc
...@@ -539,7 +539,7 @@ module.exports = (function() { ...@@ -539,7 +539,7 @@ module.exports = (function() {
} }
if (dataType.autoIncrement) { if (dataType.autoIncrement) {
template +=" SERIAL" template += " SERIAL"
} }
if (dataType.defaultValue !== undefined) { if (dataType.defaultValue !== undefined) {
...@@ -754,6 +754,7 @@ module.exports = (function() { ...@@ -754,6 +754,7 @@ module.exports = (function() {
Utils._.forEach(attrValueHash, function(value, key, hash) { Utils._.forEach(attrValueHash, function(value, key, hash) {
if (tables[tableName] && tables[tableName][key]) { if (tables[tableName] && tables[tableName][key]) {
switch (tables[tableName][key]) { switch (tables[tableName][key]) {
case 'bigserial':
case 'serial': case 'serial':
delete hash[key] delete hash[key]
returning.push(key) returning.push(key)
......
...@@ -426,6 +426,34 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() { ...@@ -426,6 +426,34 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
}) })
}) })
it('can omitt autoincremental columns', function(done) {
var self = this
, data = { title: 'Iliad' }
, dataTypes = [Sequelize.INTEGER, Sequelize.BIGINT]
dataTypes.forEach(function(dataType, index) {
var Book = self.sequelize.define('Book'+index, {
id: { type: dataType, primaryKey: true, autoIncrement: true },
title: Sequelize.TEXT
})
Book.sync({ force: true }).success(function() {
Book
.create(data)
.success(function(book) {
expect(book.title).toEqual(data.title)
expect(book.author).toEqual(data.author)
expect(Book.rawAttributes.id.type.toString())
.toEqual(dataTypes[index].toString())
Book.drop();
if (index >= dataTypes.length - 1) {
done()
}
})
})
})
})
it('saves data with single quote', function(done) { it('saves data with single quote', function(done) {
var quote = "single'quote" var quote = "single'quote"
, self = this , self = this
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!