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 ff5db2f1
authored
Nov 17, 2013
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
one last test + fix for has_one
1 parent
27ba66e5
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
3 deletions
lib/associations/has-one.js
test/associations/has-many.test.js
test/associations/has-one.test.js
lib/associations/has-one.js
View file @
ff5db2f
...
@@ -88,7 +88,7 @@ module.exports = (function() {
...
@@ -88,7 +88,7 @@ module.exports = (function() {
oldObj
[
self
.
identifier
]
=
null
oldObj
[
self
.
identifier
]
=
null
oldObj
oldObj
.
save
(
.
save
(
Utils
.
_
.
extend
(
options
,
{
Utils
.
_
.
extend
(
{},
options
,
{
fields
:
[
self
.
identifier
],
fields
:
[
self
.
identifier
],
allowNull
:
[
self
.
identifier
]
allowNull
:
[
self
.
identifier
]
})
})
...
...
test/associations/has-many.test.js
View file @
ff5db2f
...
@@ -217,12 +217,12 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
...
@@ -217,12 +217,12 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
sequelize
.
transaction
(
function
(
t
)
{
sequelize
.
transaction
(
function
(
t
)
{
article
.
setLabels
([
label
],
{
transaction
:
t
}).
success
(
function
()
{
article
.
setLabels
([
label
],
{
transaction
:
t
}).
success
(
function
()
{
Label
Label
.
findAll
({
where
:
{
a
rticleId
:
article
.
id
},
transaction
:
undefined
})
.
findAll
({
where
:
{
A
rticleId
:
article
.
id
},
transaction
:
undefined
})
.
success
(
function
(
labels
)
{
.
success
(
function
(
labels
)
{
expect
(
labels
.
length
).
to
.
equal
(
0
)
expect
(
labels
.
length
).
to
.
equal
(
0
)
Label
Label
.
findAll
({
where
:
{
a
rticleId
:
article
.
id
},
transaction
:
t
})
.
findAll
({
where
:
{
A
rticleId
:
article
.
id
},
transaction
:
t
})
.
success
(
function
(
labels
)
{
.
success
(
function
(
labels
)
{
expect
(
labels
.
length
).
to
.
equal
(
1
)
expect
(
labels
.
length
).
to
.
equal
(
1
)
t
.
rollback
().
success
(
function
()
{
done
()
})
t
.
rollback
().
success
(
function
()
{
done
()
})
...
...
test/associations/has-one.test.js
View file @
ff5db2f
...
@@ -75,9 +75,36 @@ describe(Support.getTestDialectTeaser("HasOne"), function() {
...
@@ -75,9 +75,36 @@ describe(Support.getTestDialectTeaser("HasOne"), function() {
})
})
describe
(
'setAssociation'
,
function
()
{
describe
(
'setAssociation'
,
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
.
hasOne
(
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
t
.
rollback
().
success
(
function
()
{
done
()
})
})
})
})
})
})
})
})
})
})
it
(
'can set an association with predefined primary keys'
,
function
(
done
)
{
it
(
'can set an association with predefined primary keys'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'UserXYZZ'
,
{
userCoolIdTag
:
{
type
:
Sequelize
.
INTEGER
,
primaryKey
:
true
},
username
:
Sequelize
.
STRING
})
var
User
=
this
.
sequelize
.
define
(
'UserXYZZ'
,
{
userCoolIdTag
:
{
type
:
Sequelize
.
INTEGER
,
primaryKey
:
true
},
username
:
Sequelize
.
STRING
})
,
Task
=
this
.
sequelize
.
define
(
'TaskXYZZ'
,
{
taskOrSomething
:
{
type
:
Sequelize
.
INTEGER
,
primaryKey
:
true
},
title
:
Sequelize
.
STRING
})
,
Task
=
this
.
sequelize
.
define
(
'TaskXYZZ'
,
{
taskOrSomething
:
{
type
:
Sequelize
.
INTEGER
,
primaryKey
:
true
},
title
:
Sequelize
.
STRING
})
,
self
=
this
User
.
hasOne
(
Task
,
{
foreignKey
:
'userCoolIdTag'
})
User
.
hasOne
(
Task
,
{
foreignKey
:
'userCoolIdTag'
})
...
...
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