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 aad9eeed
authored
Jun 26, 2014
by
Jan Scheurer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix bug in hasMany.set when models have custom primary keys, add unit test
1 parent
8f2092a9
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
2 deletions
lib/associations/has-many-double-linked.js
test/associations/has-many.test.js
lib/associations/has-many-double-linked.js
View file @
aad9eee
...
@@ -105,13 +105,13 @@ module.exports = (function() {
...
@@ -105,13 +105,13 @@ module.exports = (function() {
unassociatedObjects
=
newAssociations
.
filter
(
function
(
obj
)
{
unassociatedObjects
=
newAssociations
.
filter
(
function
(
obj
)
{
return
!
Utils
.
_
.
find
(
oldAssociations
,
function
(
old
)
{
return
!
Utils
.
_
.
find
(
oldAssociations
,
function
(
old
)
{
return
(
!!
obj
[
foreignIdentifier
]
&&
!!
old
[
foreignIdentifier
]
?
obj
[
foreignIdentifier
]
===
old
[
foreignIdentifier
]
:
obj
.
id
===
old
.
id
)
return
(
!!
obj
[
foreignIdentifier
]
?
obj
[
foreignIdentifier
]
===
old
[
foreignIdentifier
]
:
(
!!
obj
[
targetKeys
[
0
]]
?
obj
[
targetKeys
[
0
]]
===
old
[
targetKeys
[
0
]]
:
obj
.
id
===
old
.
id
)
)
})
})
})
})
oldAssociations
.
forEach
(
function
(
old
)
{
oldAssociations
.
forEach
(
function
(
old
)
{
var
newObj
=
Utils
.
_
.
find
(
newAssociations
,
function
(
obj
)
{
var
newObj
=
Utils
.
_
.
find
(
newAssociations
,
function
(
obj
)
{
return
(
!!
obj
[
foreignIdentifier
]
&&
!!
old
[
foreignIdentifier
]
?
obj
[
foreignIdentifier
]
===
old
[
foreignIdentifier
]
:
obj
.
id
===
old
.
id
)
return
(
!!
obj
[
foreignIdentifier
]
?
obj
[
foreignIdentifier
]
===
old
[
foreignIdentifier
]
:
(
!!
obj
[
targetKeys
[
0
]]
?
obj
[
targetKeys
[
0
]]
===
old
[
targetKeys
[
0
]]
:
obj
.
id
===
old
.
id
)
)
})
})
if
(
!
newObj
)
{
if
(
!
newObj
)
{
...
...
test/associations/has-many.test.js
View file @
aad9eee
...
@@ -680,6 +680,34 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
...
@@ -680,6 +680,34 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
})
})
})
})
it
(
"sets new associations with custom primary keys"
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
uid
:
{
type
:
DataTypes
.
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
},
username
:
DataTypes
.
STRING
})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
tid
:
{
type
:
DataTypes
.
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
},
title
:
DataTypes
.
STRING
})
User
.
hasMany
(
Task
)
Task
.
hasMany
(
User
)
User
.
sync
({
force
:
true
}).
success
(
function
()
{
Task
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
}).
success
(
function
(
user
)
{
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
task
.
setUsers
([
user
]).
success
(
function
()
{
User
.
create
({
username
:
'bar'
}).
success
(
function
(
user2
)
{
user2
.
user_has_task
=
{
usertitle
:
"Something"
};
task
.
setUsers
([
user
,
user2
]).
success
(
function
()
{
task
.
getUsers
().
success
(
function
(
_users
)
{
expect
(
_users
).
to
.
have
.
length
(
2
)
done
()
})
})
})
})
})
})
})
})
})
it
(
"joins an association with custom primary keys"
,
function
(
done
)
{
it
(
"joins an association with custom primary keys"
,
function
(
done
)
{
var
Group
=
this
.
sequelize
.
define
(
'group'
,
{
var
Group
=
this
.
sequelize
.
define
(
'group'
,
{
group_id
:
{
type
:
DataTypes
.
INTEGER
,
primaryKey
:
true
},
group_id
:
{
type
:
DataTypes
.
INTEGER
,
primaryKey
:
true
},
...
...
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