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 3c31bca0
authored
Nov 17, 2013
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more transaction tests
1 parent
9f99f42d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
2 deletions
lib/associations/has-many.js
test/associations/has-many.test.js
lib/associations/has-many.js
View file @
3c31bca
...
...
@@ -124,10 +124,10 @@ module.exports = (function() {
return
new
Class
(
self
,
this
).
injectGetter
(
options
)
}
obj
[
this
.
accessors
.
hasAll
]
=
function
(
objects
)
{
obj
[
this
.
accessors
.
hasAll
]
=
function
(
objects
,
options
)
{
var
instance
=
this
;
var
customEventEmitter
=
new
Utils
.
CustomEventEmitter
(
function
()
{
instance
[
self
.
accessors
.
get
]()
instance
[
self
.
accessors
.
get
](
options
)
.
error
(
function
(
err
)
{
customEventEmitter
.
emit
(
'error'
,
err
)
})
.
success
(
function
(
associatedObjects
)
{
customEventEmitter
.
emit
(
'success'
,
...
...
test/associations/has-many.test.js
View file @
3c31bca
...
...
@@ -137,6 +137,37 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
})
})
it
(
'supports transactions'
,
function
(
done
)
{
Support
.
prepareTransactionTest
(
this
.
sequelize
,
function
(
sequelize
)
{
var
Article
=
sequelize
.
define
(
'Article'
,
{
'title'
:
DataTypes
.
STRING
})
,
Label
=
sequelize
.
define
(
'Label'
,
{
'text'
:
DataTypes
.
STRING
})
Article
.
hasMany
(
Label
)
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
Article
.
create
({
title
:
'foo'
}).
success
(
function
(
article
)
{
Label
.
create
({
text
:
'bar'
}).
success
(
function
(
label
)
{
sequelize
.
transaction
(
function
(
t
)
{
article
.
setLabels
([
label
],
{
transaction
:
t
}).
success
(
function
()
{
Article
.
all
({
transaction
:
t
}).
success
(
function
(
articles
)
{
articles
[
0
].
hasLabels
([
label
]).
success
(
function
(
hasLabel
)
{
expect
(
hasLabel
).
to
.
be
.
false
Article
.
all
({
transaction
:
t
}).
success
(
function
(
articles
)
{
articles
[
0
].
hasLabels
([
label
],
{
transaction
:
t
}).
success
(
function
(
hasLabel
)
{
expect
(
hasLabel
).
to
.
be
.
true
t
.
rollback
().
success
(
function
()
{
done
()
})
})
})
})
})
})
})
})
})
})
})
})
it
(
'answers false if only some labels have been assigned'
,
function
(
done
)
{
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
([
this
.
Article
.
create
({
title
:
'Article'
}),
...
...
@@ -173,6 +204,38 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
})
describe
(
'setAssociations'
,
function
()
{
it
(
'supports transactions'
,
function
(
done
)
{
Support
.
prepareTransactionTest
(
this
.
sequelize
,
function
(
sequelize
)
{
var
Article
=
sequelize
.
define
(
'Article'
,
{
'title'
:
DataTypes
.
STRING
})
,
Label
=
sequelize
.
define
(
'Label'
,
{
'text'
:
DataTypes
.
STRING
})
Article
.
hasMany
(
Label
)
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
Article
.
create
({
title
:
'foo'
}).
success
(
function
(
article
)
{
Label
.
create
({
text
:
'bar'
}).
success
(
function
(
label
)
{
sequelize
.
transaction
(
function
(
t
)
{
article
.
setLabels
([
label
],
{
transaction
:
t
}).
success
(
function
()
{
Label
.
findAll
({
where
:
{
articleId
:
article
.
id
},
transaction
:
undefined
})
.
success
(
function
(
labels
)
{
expect
(
labels
.
length
).
to
.
equal
(
0
)
Label
.
findAll
({
where
:
{
articleId
:
article
.
id
},
transaction
:
t
})
.
success
(
function
(
labels
)
{
expect
(
labels
.
length
).
to
.
equal
(
1
)
t
.
rollback
().
success
(
function
()
{
done
()
})
})
})
})
})
})
})
})
})
})
it
(
"clears associations when passing null to the set-method"
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
DataTypes
.
STRING
})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
DataTypes
.
STRING
})
...
...
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