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

Commit aa33ecb6 by Mick Hansen

Merge branch 'master' into milestones/2.0.0

2 parents ac691957 8babe6ca
......@@ -10,7 +10,7 @@ Notice: All 1.7.x changed are present in 2.0.x aswell
- `sequelize --undo` will now actually undo migrations. Its basically an alias for `sequelize --migrate --undo`. [#1059](https://github.com/sequelize/sequelize/pull/1059)
- fix bug where `{where: {ne: null}}` would result in `!= NULL` instead of `IS NOT NULL` [#1231](https://github.com/sequelize/sequelize/pull/1059)
- fixes a bug with validation skipping using the `fields` options. [#1233](https://github.com/sequelize/sequelize/pull/1233)
- fixes a bug with postgres and setters [#1234](https://github.com/sequelize/sequelize/issues/123)
- fixes a bug with postgres and setters [#1234](https://github.com/sequelize/sequelize/issues/1234)
#### Backwards compatability changes
- Hooks are no longer passing value hashes. Instead, they are now passing instances of the model.
......
......@@ -254,10 +254,11 @@ module.exports = {
get ENUM() {
var result = function() {
return {
type: 'ENUM',
type: 'ENUM',
values: Array.prototype.slice.call(arguments).reduce(function(result, element) {
return result.concat(Array.isArray(element) ? element : [ element ])
}, [])
}, []),
toString: result.toString
}
}
......
......@@ -203,6 +203,13 @@ module.exports = (function() {
// If you don't specify a valid data type lets help you debug it
Utils._.each(attributes, function(dataType, name) {
if (Utils.isHash(dataType)) {
// We have special cases where the type is an object containing
// the values (e.g. Sequelize.ENUM(value, value2) returns an object
// instead of a function)
// Copy these values to the dataType
dataType.values = (dataType.type && dataType.type.values) || dataType.values;
// We keep on working with the actual type object
dataType = dataType.type
}
......
......@@ -651,6 +651,62 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
describe('when defined via { field: Sequelize.ENUM }', function() {
it('allows values passed as parameters', function(done) {
var Enum = this.sequelize.define('Enum', {
state: Sequelize.ENUM('happy', 'sad')
})
Enum.sync({ force: true }).success(function() {
Enum.create({ state: 'happy' }).success(function(_item) {
done()
});
});
})
it('allows values passed as an array', function(done) {
var Enum = this.sequelize.define('Enum', {
state: Sequelize.ENUM(['happy', 'sad'])
})
Enum.sync({ force: true }).success(function() {
Enum.create({ state: 'happy' }).success(function(_item) {
done()
});
});
})
})
describe('when defined via { field: { type: Sequelize.ENUM } }', function() {
it('allows values passed as parameters', function(done) {
var Enum = this.sequelize.define('Enum', {
state: {
type: Sequelize.ENUM('happy', 'sad')
}
})
Enum.sync({ force: true }).success(function() {
Enum.create({ state: 'happy' }).success(function(_item) {
done()
});
});
})
it('allows values passed as an array', function(done) {
var Enum = this.sequelize.define('Enum', {
state: {
type: Sequelize.ENUM(['happy', 'sad'])
}
})
Enum.sync({ force: true }).success(function() {
Enum.create({ state: 'happy' }).success(function(_item) {
done()
});
});
})
})
describe('can safely sync multiple times', function(done) {
it('through the factory', function(done) {
var Enum = this.sequelize.define('Enum', {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!