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
不要怂,就是干,撸起袖子干!
You need to sign in or sign up before continuing.
Commit 0bfc4e31
authored
Mar 11, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix uuid default values for primary keys named id
1 parent
77f3c2b4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
5 deletions
lib/dao.js
test/dao-factory/create.test.js
test/dao.test.js
lib/dao.js
View file @
0bfc4e3
...
...
@@ -649,10 +649,6 @@ module.exports = (function() {
if
(
options
.
isNewRecord
)
{
defaults
=
{}
// set id to null if not passed as value, a newly created dao has no id
// removing this breaks bulkCreate
defaults
[
this
.
Model
.
primaryKeyAttribute
]
=
null
;
if
(
this
.
Model
.
_hasDefaultValues
)
{
Utils
.
_
.
each
(
this
.
Model
.
_defaultValues
,
function
(
valueFn
,
key
)
{
if
(
!
defaults
.
hasOwnProperty
(
key
))
{
...
...
@@ -661,6 +657,13 @@ module.exports = (function() {
})
}
// set id to null if not passed as value, a newly created dao has no id
// removing this breaks bulkCreate
// do after default values since it might have UUID as a default value
if
(
!
defaults
.
hasOwnProperty
(
this
.
Model
.
primaryKeyAttribute
))
{
defaults
[
this
.
Model
.
primaryKeyAttribute
]
=
null
;
}
if
(
this
.
Model
.
_timestampAttributes
.
createdAt
&&
defaults
[
this
.
Model
.
_timestampAttributes
.
createdAt
])
{
this
.
dataValues
[
this
.
Model
.
_timestampAttributes
.
createdAt
]
=
Utils
.
toDefaultValue
(
defaults
[
this
.
Model
.
_timestampAttributes
.
createdAt
]);
delete
defaults
[
this
.
Model
.
_timestampAttributes
.
createdAt
];
...
...
test/dao-factory/create.test.js
View file @
0bfc4e3
...
...
@@ -130,6 +130,30 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
describe
(
'create'
,
function
()
{
it
(
'works with non-integer primary keys'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
'id'
:
{
primaryKey
:
true
,
type
:
DataTypes
.
UUID
,
defaultValue
:
DataTypes
.
UUIDV4
},
'email'
:
{
type
:
DataTypes
.
UUID
,
defaultValue
:
DataTypes
.
UUIDV4
}
})
this
.
sequelize
.
sync
({
force
:
true
}).
done
(
function
(
err
)
{
expect
(
err
).
not
.
to
.
be
.
ok
User
.
create
({}).
done
(
function
(
err
,
user
)
{
expect
(
err
).
not
.
to
.
be
.
ok
expect
(
user
).
to
.
be
.
ok
expect
(
user
.
id
).
to
.
be
.
ok
done
()
})
})
})
it
(
'supports transactions'
,
function
(
done
)
{
var
self
=
this
...
...
@@ -436,7 +460,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
done
()
})
})
}).
error
(
done
)
}).
error
(
done
)
})
})
...
...
test/dao.test.js
View file @
0bfc4e3
...
...
@@ -661,6 +661,20 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
expect
(
uuid
.
parse
(
user
.
uuidv4
)).
to
.
have
.
length
(
16
)
done
()
})
it
(
'should store a valid uuid if the field is a primary key named id'
,
function
()
{
var
Person
=
this
.
sequelize
.
define
(
'Person'
,
{
id
:
{
type
:
DataTypes
.
UUID
,
defaultValue
:
DataTypes
.
UUIDV1
,
primaryKey
:
true
}
})
var
person
=
Person
.
build
({})
expect
(
person
.
id
).
to
.
be
.
ok
expect
(
person
.
id
).
to
.
have
.
length
(
36
)
})
})
describe
(
'current date'
,
function
()
{
it
(
'should store a date in touchedAt'
,
function
(
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