Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit 48a861d4
authored
Aug 26, 2013
by
Sascha Depold
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #857 from durango/enum-null
Enum values can now be null
2 parents
d633069a
202aeedd
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
2 deletions
lib/dao-factory.js
lib/dao.js
test/dao-factory.test.js
lib/dao-factory.js
View file @
48a861d
...
...
@@ -608,7 +608,7 @@ module.exports = (function() {
,
hasValue
=
(
typeof
values
[
attrName
]
!==
'undefined'
)
,
valueOutOfScope
=
((
definition
.
values
||
[]).
indexOf
(
values
[
attrName
])
===
-
1
)
if
(
isEnum
&&
hasValue
&&
valueOutOfScope
)
{
if
(
isEnum
&&
hasValue
&&
valueOutOfScope
&&
!
(
definition
.
allowNull
===
true
&&
values
[
attrName
]
===
null
)
)
{
throw
new
Error
(
'Value "'
+
values
[
attrName
]
+
'" for ENUM '
+
attrName
+
' is out of allowed scope. Allowed values: '
+
definition
.
values
.
join
(
', '
))
}
}
...
...
lib/dao.js
View file @
48a861d
...
...
@@ -152,7 +152,7 @@ module.exports = (function() {
valueOutOfScope
=
((
definition
.
values
||
[]).
indexOf
(
values
[
attrName
])
===
-
1
)
}
if
(
isEnum
&&
hasValue
&&
valueOutOfScope
)
{
if
(
isEnum
&&
hasValue
&&
valueOutOfScope
&&
!
(
definition
.
allowNull
===
true
&&
values
[
attrName
]
===
null
)
)
{
throw
new
Error
(
'Value "'
+
values
[
attrName
]
+
'" for ENUM '
+
attrName
+
' is out of allowed scope. Allowed values: '
+
definition
.
values
.
join
(
', '
))
}
...
...
test/dao-factory.test.js
View file @
48a861d
...
...
@@ -593,6 +593,23 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
})
it
(
'allows null values'
,
function
(
done
)
{
var
Enum
=
this
.
sequelize
.
define
(
'Enum'
,
{
state
:
{
type
:
Sequelize
.
ENUM
,
values
:
[
'happy'
,
'sad'
],
allowNull
:
true
}
})
Enum
.
sync
({
force
:
true
}).
success
(
function
()
{
Enum
.
create
({
state
:
null
}).
success
(
function
(
_enum
)
{
expect
(
_enum
.
state
).
to
.
be
.
null
done
()
})
})
})
})
})
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment