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 42ede1e9
authored
Nov 16, 2013
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
transaction support for belongs to getters
1 parent
c480c35b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
3 deletions
lib/associations/belongs-to.js
test/associations/belongs-to.test.js
lib/associations/belongs-to.js
View file @
42ede1e
...
@@ -45,8 +45,9 @@ module.exports = (function() {
...
@@ -45,8 +45,9 @@ module.exports = (function() {
,
primaryKey
=
primaryKeys
.
length
===
1
?
primaryKeys
[
0
]
:
'id'
,
primaryKey
=
primaryKeys
.
length
===
1
?
primaryKeys
[
0
]
:
'id'
obj
[
accessor
]
=
function
(
params
)
{
obj
[
accessor
]
=
function
(
params
)
{
var
id
=
this
[
self
.
identifier
]
var
id
=
this
[
self
.
identifier
]
,
where
=
{}
,
where
=
{}
,
options
=
Utils
.
_
.
pick
(
params
||
{},
'transaction'
)
where
[
primaryKey
]
=
id
where
[
primaryKey
]
=
id
...
@@ -60,7 +61,7 @@ module.exports = (function() {
...
@@ -60,7 +61,7 @@ module.exports = (function() {
params
=
id
params
=
id
}
}
return
self
.
target
.
find
(
params
)
return
self
.
target
.
find
(
params
,
options
)
}
}
return
this
return
this
...
...
test/associations/belongs-to.test.js
View file @
42ede1e
...
@@ -20,6 +20,39 @@ describe(Support.getTestDialectTeaser("BelongsTo"), function() {
...
@@ -20,6 +20,39 @@ describe(Support.getTestDialectTeaser("BelongsTo"), function() {
})
})
})
})
describe
(
'getAssociation'
,
function
()
{
it
(
'supports transactions'
,
function
(
done
)
{
Support
.
prepareTransactionTest
(
this
.
sequelize
,
function
(
sequelize
)
{
var
User
=
sequelize
.
define
(
'User'
,
{
username
:
Support
.
Sequelize
.
STRING
})
,
Group
=
sequelize
.
define
(
'Group'
,
{
name
:
Support
.
Sequelize
.
STRING
})
Group
.
belongsTo
(
User
)
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
}).
success
(
function
(
user
)
{
Group
.
create
({
name
:
'bar'
}).
success
(
function
(
group
)
{
sequelize
.
transaction
(
function
(
t
)
{
group
.
setUser
(
user
,
{
transaction
:
t
}).
success
(
function
()
{
Group
.
all
().
success
(
function
(
groups
)
{
groups
[
0
].
getUser
().
success
(
function
(
associatedUser
)
{
expect
(
associatedUser
).
to
.
be
.
null
Group
.
all
({
transaction
:
t
}).
success
(
function
(
groups
)
{
groups
[
0
].
getUser
({
transaction
:
t
}).
success
(
function
(
associatedUser
)
{
expect
(
associatedUser
).
to
.
be
.
not
.
null
t
.
rollback
().
success
(
function
()
{
done
()
})
})
})
})
})
})
})
})
})
})
})
})
})
describe
(
'setAssociation'
,
function
()
{
describe
(
'setAssociation'
,
function
()
{
it
(
'supports transactions'
,
function
(
done
)
{
it
(
'supports transactions'
,
function
(
done
)
{
Support
.
prepareTransactionTest
(
this
.
sequelize
,
function
(
sequelize
)
{
Support
.
prepareTransactionTest
(
this
.
sequelize
,
function
(
sequelize
)
{
...
...
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