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 9885aca4
authored
Apr 03, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1:M createAssociation should only use one query and fix transactions for createAssociation
1 parent
587ec3ad
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
6 deletions
lib/associations/has-many.js
test/associations/has-many.test.js
lib/associations/has-many.js
View file @
9885aca
...
...
@@ -394,9 +394,9 @@ module.exports = (function() {
if
((
fieldsOrOptions
||
{}).
transaction
instanceof
Transaction
)
{
options
.
transaction
=
fieldsOrOptions
.
transaction
delete
fieldsOrOptions
.
transaction
}
if
(
Object
(
self
.
through
)
===
self
.
through
)
{
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
// Create the related model instance
self
.
target
...
...
@@ -407,6 +407,10 @@ module.exports = (function() {
.
proxy
(
emitter
)
})
}).
run
()
}
else
{
values
[
self
.
identifier
]
=
instance
.
get
(
self
.
source
.
primaryKeyAttribute
);
return
self
.
target
.
create
(
values
,
fieldsOrOptions
)
}
}
return
this
...
...
test/associations/has-many.test.js
View file @
9885aca
...
...
@@ -349,12 +349,16 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
it
(
'creates the object with the association directly'
,
function
(
done
)
{
var
spy
=
sinon
.
spy
()
var
Article
=
this
.
sequelize
.
define
(
'Article'
,
{
'title'
:
DataTypes
.
STRING
})
,
Label
=
this
.
sequelize
.
define
(
'Label'
,
{
'text'
:
DataTypes
.
STRING
,
var
Article
=
this
.
sequelize
.
define
(
'Article'
,
{
'title'
:
DataTypes
.
STRING
}),
Label
=
this
.
sequelize
.
define
(
'Label'
,
{
'text'
:
DataTypes
.
STRING
,
'ArticleId'
:
{
type
:
DataTypes
.
INTEGER
,
allowNull
:
false
}})
}
})
Article
.
hasMany
(
Label
)
...
...
@@ -362,7 +366,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
Label
.
sync
({
force
:
true
}).
success
(
function
()
{
Article
.
create
({
title
:
'foo'
}).
success
(
function
(
article
)
{
article
.
createLabel
({
text
:
'bar'
}).
on
(
'sql'
,
spy
).
complete
(
function
(
err
,
label
)
{
expect
(
err
).
to
.
not
.
be
.
ok
expect
(
err
).
not
.
to
.
be
.
ok
expect
(
spy
.
calledOnce
).
to
.
be
.
true
expect
(
label
.
ArticleId
).
to
.
equal
(
article
.
id
)
done
()
...
...
@@ -384,7 +388,9 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
Label
.
sync
({
force
:
true
}).
success
(
function
()
{
Article
.
create
({
title
:
'foo'
}).
success
(
function
(
article
)
{
sequelize
.
transaction
(
function
(
t
)
{
article
.
createLabel
({
text
:
'bar'
},
{
transaction
:
t
}).
success
(
function
(
label
)
{
article
.
createLabel
({
text
:
'bar'
},
{
transaction
:
t
}).
success
(
function
()
{
Label
.
findAll
().
success
(
function
(
labels
)
{
expect
(
labels
.
length
).
to
.
equal
(
0
);
Label
.
findAll
({
where
:
{
ArticleId
:
article
.
id
}}).
success
(
function
(
labels
)
{
expect
(
labels
.
length
).
to
.
equal
(
0
)
Label
.
findAll
({
where
:
{
ArticleId
:
article
.
id
}},
{
transaction
:
t
}).
success
(
function
(
labels
)
{
...
...
@@ -400,6 +406,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
})
})
})
})
describe
(
"getting assocations with options"
,
function
()
{
beforeEach
(
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