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 bc5c30bb
authored
Jan 11, 2014
by
Sascha Gehlich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sequelize.ENUM can now take values as arguments or as a single array argument
1 parent
20cf37f7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
2 deletions
lib/data-types.js
lib/dialects/mysql/query-generator.js
test/dao-factory/create.test.js
lib/data-types.js
View file @
bc5c30b
...
@@ -254,10 +254,11 @@ module.exports = {
...
@@ -254,10 +254,11 @@ module.exports = {
get
ENUM
()
{
get
ENUM
()
{
var
result
=
function
()
{
var
result
=
function
()
{
return
{
return
{
type
:
'ENUM'
,
type
:
'ENUM'
,
values
:
Array
.
prototype
.
slice
.
call
(
arguments
).
reduce
(
function
(
result
,
element
)
{
values
:
Array
.
prototype
.
slice
.
call
(
arguments
).
reduce
(
function
(
result
,
element
)
{
return
result
.
concat
(
Array
.
isArray
(
element
)
?
element
:
[
element
])
return
result
.
concat
(
Array
.
isArray
(
element
)
?
element
:
[
element
])
},
[])
},
[]),
toString
:
result
.
toString
}
}
}
}
...
...
lib/dialects/mysql/query-generator.js
View file @
bc5c30b
...
@@ -292,6 +292,12 @@ module.exports = (function() {
...
@@ -292,6 +292,12 @@ module.exports = (function() {
if
(
Utils
.
isHash
(
dataType
))
{
if
(
Utils
.
isHash
(
dataType
))
{
var
template
var
template
// 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
.
values
||
dataType
.
values
;
if
(
dataType
.
type
.
toString
()
===
DataTypes
.
ENUM
.
toString
())
{
if
(
dataType
.
type
.
toString
()
===
DataTypes
.
ENUM
.
toString
())
{
if
(
Array
.
isArray
(
dataType
.
values
)
&&
(
dataType
.
values
.
length
>
0
))
{
if
(
Array
.
isArray
(
dataType
.
values
)
&&
(
dataType
.
values
.
length
>
0
))
{
template
=
"ENUM("
+
Utils
.
_
.
map
(
dataType
.
values
,
function
(
value
)
{
template
=
"ENUM("
+
Utils
.
_
.
map
(
dataType
.
values
,
function
(
value
)
{
...
...
test/dao-factory/create.test.js
View file @
bc5c30b
...
@@ -651,6 +651,34 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
...
@@ -651,6 +651,34 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
})
})
it
(
'allows values passed as parameters to Sequelize.ENUM'
,
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 to Sequelize.ENUM'
,
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
)
{
describe
(
'can safely sync multiple times'
,
function
(
done
)
{
it
(
'through the factory'
,
function
(
done
)
{
it
(
'through the factory'
,
function
(
done
)
{
var
Enum
=
this
.
sequelize
.
define
(
'Enum'
,
{
var
Enum
=
this
.
sequelize
.
define
(
'Enum'
,
{
...
...
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