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 786b19b9
authored
Mar 10, 2019
by
Sushant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(build): default null for multiple primary keys
1 parent
ae7d4b96
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
9 deletions
lib/model.js
test/integration/instance.test.js
test/integration/model/create.test.js
lib/model.js
View file @
786b19b
...
@@ -123,8 +123,12 @@ class Model {
...
@@ -123,8 +123,12 @@ class Model {
// set id to null if not passed as value, a newly created dao has no id
// set id to null if not passed as value, a newly created dao has no id
// removing this breaks bulkCreate
// removing this breaks bulkCreate
// do after default values since it might have UUID as a default value
// do after default values since it might have UUID as a default value
if
(
this
.
constructor
.
primaryKeyAttribute
&&
!
defaults
.
hasOwnProperty
(
this
.
constructor
.
primaryKeyAttribute
))
{
if
(
this
.
constructor
.
primaryKeyAttributes
.
length
)
{
defaults
[
this
.
constructor
.
primaryKeyAttribute
]
=
null
;
this
.
constructor
.
primaryKeyAttributes
.
forEach
(
primaryKeyAttribute
=>
{
if
(
!
defaults
.
hasOwnProperty
(
primaryKeyAttribute
))
{
defaults
[
primaryKeyAttribute
]
=
null
;
}
});
}
}
if
(
this
.
constructor
.
_timestampAttributes
.
createdAt
&&
defaults
[
this
.
constructor
.
_timestampAttributes
.
createdAt
])
{
if
(
this
.
constructor
.
_timestampAttributes
.
createdAt
&&
defaults
[
this
.
constructor
.
_timestampAttributes
.
createdAt
])
{
...
...
test/integration/instance.test.js
View file @
786b19b
...
@@ -136,9 +136,14 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
...
@@ -136,9 +136,14 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
expect
(
isUUID
(
user
.
uuidv4
,
4
)).
to
.
be
.
true
;
expect
(
isUUID
(
user
.
uuidv4
,
4
)).
to
.
be
.
true
;
});
});
it
(
'should store a valid uuid if the
field is a primary key named i
d'
,
function
()
{
it
(
'should store a valid uuid if the
multiple primary key fields use
d'
,
function
()
{
const
Person
=
this
.
sequelize
.
define
(
'Person'
,
{
const
Person
=
this
.
sequelize
.
define
(
'Person'
,
{
id
:
{
id1
:
{
type
:
DataTypes
.
UUID
,
defaultValue
:
DataTypes
.
UUIDV1
,
primaryKey
:
true
},
id2
:
{
type
:
DataTypes
.
UUID
,
type
:
DataTypes
.
UUID
,
defaultValue
:
DataTypes
.
UUIDV1
,
defaultValue
:
DataTypes
.
UUIDV1
,
primaryKey
:
true
primaryKey
:
true
...
@@ -146,8 +151,11 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
...
@@ -146,8 +151,11 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
});
});
const
person
=
Person
.
build
({});
const
person
=
Person
.
build
({});
expect
(
person
.
id
).
to
.
be
.
ok
;
expect
(
person
.
id1
).
to
.
be
.
ok
;
expect
(
person
.
id
).
to
.
have
.
length
(
36
);
expect
(
person
.
id1
).
to
.
have
.
length
(
36
);
expect
(
person
.
id2
).
to
.
be
.
ok
;
expect
(
person
.
id2
).
to
.
have
.
length
(
36
);
});
});
});
});
describe
(
'current date'
,
()
=>
{
describe
(
'current date'
,
()
=>
{
...
...
test/integration/model/create.test.js
View file @
786b19b
...
@@ -586,9 +586,14 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -586,9 +586,14 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
describe
(
'create'
,
()
=>
{
describe
(
'create'
,
()
=>
{
it
(
'works with non-integer primary keys with a default value'
,
function
()
{
it
(
'works with
multiple
non-integer primary keys with a default value'
,
function
()
{
const
User
=
this
.
sequelize
.
define
(
'User'
,
{
const
User
=
this
.
sequelize
.
define
(
'User'
,
{
'id'
:
{
'id1'
:
{
primaryKey
:
true
,
type
:
DataTypes
.
UUID
,
defaultValue
:
DataTypes
.
UUIDV4
},
'id2'
:
{
primaryKey
:
true
,
primaryKey
:
true
,
type
:
DataTypes
.
UUID
,
type
:
DataTypes
.
UUID
,
defaultValue
:
DataTypes
.
UUIDV4
defaultValue
:
DataTypes
.
UUIDV4
...
@@ -602,7 +607,8 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -602,7 +607,8 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return
this
.
sequelize
.
sync
({
force
:
true
}).
then
(()
=>
{
return
this
.
sequelize
.
sync
({
force
:
true
}).
then
(()
=>
{
return
User
.
create
({}).
then
(
user
=>
{
return
User
.
create
({}).
then
(
user
=>
{
expect
(
user
).
to
.
be
.
ok
;
expect
(
user
).
to
.
be
.
ok
;
expect
(
user
.
id
).
to
.
be
.
ok
;
expect
(
user
.
id1
).
to
.
be
.
ok
;
expect
(
user
.
id2
).
to
.
be
.
ok
;
});
});
});
});
});
});
...
...
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