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 a54a7a5e
authored
Feb 03, 2018
by
Claire L
Committed by
Sushant
Feb 03, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(model/findOrBuild): handle includes (#8938)
1 parent
d65a95c9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
1 deletions
lib/model.js
test/integration/model/findOrBuild.test.js
lib/model.js
View file @
a54a7a5
...
@@ -2058,7 +2058,7 @@ class Model {
...
@@ -2058,7 +2058,7 @@ class Model {
values
=
Utils
.
defaults
(
values
,
options
.
where
);
values
=
Utils
.
defaults
(
values
,
options
.
where
);
}
}
instance
=
this
.
build
(
values
);
instance
=
this
.
build
(
values
,
options
);
return
Promise
.
resolve
([
instance
,
true
]);
return
Promise
.
resolve
([
instance
,
true
]);
}
}
...
...
test/integration/model/findOrBuild.test.js
0 → 100644
View file @
a54a7a5
'use strict'
;
const
chai
=
require
(
'chai'
),
expect
=
chai
.
expect
,
Support
=
require
(
__dirname
+
'/../support'
),
DataTypes
=
require
(
__dirname
+
'/../../../lib/data-types'
);
describe
(
Support
.
getTestDialectTeaser
(
'Model'
),
()
=>
{
beforeEach
(
function
()
{
this
.
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
DataTypes
.
STRING
,
age
:
DataTypes
.
INTEGER
});
this
.
Project
=
this
.
sequelize
.
define
(
'Project'
,
{
name
:
DataTypes
.
STRING
});
this
.
User
.
hasMany
(
this
.
Project
);
this
.
Project
.
belongsTo
(
this
.
User
);
return
this
.
sequelize
.
sync
({
force
:
true
});
});
describe
(
'findOrBuild'
,
()
=>
{
it
(
'initialize with includes'
,
function
()
{
return
this
.
User
.
bulkCreate
([
{
username
:
'Mello'
,
age
:
10
},
{
username
:
'Mello'
,
age
:
20
}
],
{
returning
:
true
}).
spread
((
user1
,
user2
)
=>
{
return
this
.
Project
.
create
({
name
:
'Investigate'
}).
then
(
project
=>
user2
.
setProjects
([
project
]));
}).
then
(()
=>
{
return
this
.
User
.
findOrBuild
({
defaults
:
{
username
:
'Mello'
,
age
:
10
},
where
:
{
age
:
20
},
include
:
[{
model
:
this
.
Project
}]
});
}).
spread
((
user
,
created
)
=>
{
expect
(
created
).
to
.
be
.
false
;
expect
(
user
.
get
(
'id'
)).
to
.
be
.
ok
;
expect
(
user
.
get
(
'username'
)).
to
.
equal
(
'Mello'
);
expect
(
user
.
get
(
'age'
)).
to
.
equal
(
20
);
expect
(
user
.
Projects
).
to
.
have
.
length
(
1
);
expect
(
user
.
Projects
[
0
].
get
(
'name'
)).
to
.
equal
(
'Investigate'
);
});
});
});
});
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