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 74a6b90c
authored
Jun 19, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1927 from LJ1102/master
Inject fix
2afceddc
into master, add unit test
2 parents
a3a47018
a8079153
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 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 @
74a6b90
...
@@ -110,8 +110,8 @@ module.exports = (function() {
...
@@ -110,8 +110,8 @@ module.exports = (function() {
attributes
:
Utils
.
_
.
defaults
({},
throughAttributes
,
defaultAttributes
)
attributes
:
Utils
.
_
.
defaults
({},
throughAttributes
,
defaultAttributes
)
};
};
changedAssociation
.
where
[
self
.
association
.
identifier
]
=
self
.
instance
[
s
elf
.
association
.
identifier
]
||
self
.
instance
.
id
;
changedAssociation
.
where
[
self
.
association
.
identifier
]
=
self
.
instance
[
s
ourceKeys
[
0
]
]
||
self
.
instance
.
id
;
changedAssociation
.
where
[
foreignIdentifier
]
=
newObj
[
foreignIdentifier
]
||
newObj
.
id
;
changedAssociation
.
where
[
foreignIdentifier
]
=
newObj
[
targetKeys
[
0
]
]
||
newObj
.
id
;
if
(
Object
.
keys
(
changedAssociation
.
attributes
).
length
)
{
if
(
Object
.
keys
(
changedAssociation
.
attributes
).
length
)
{
changedAssociations
.
push
(
changedAssociation
);
changedAssociations
.
push
(
changedAssociation
);
...
...
test/associations/has-many.test.js
View file @
74a6b90
...
@@ -338,6 +338,35 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
...
@@ -338,6 +338,35 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
})
})
})
})
})
})
it
(
'allows to update join table attributes with primary keys other than "id"'
,
function
()
{
var
Article
=
this
.
sequelize
.
define
(
'Article'
,
{
aid
:
{
type
:
DataTypes
.
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
},
title
:
DataTypes
.
STRING
})
,
Label
=
this
.
sequelize
.
define
(
'Label'
,
{
lid
:
{
type
:
DataTypes
.
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
},
text
:
DataTypes
.
STRING
})
,
ArticleHasLabel
=
this
.
sequelize
.
define
(
'ArticleHasLabel'
,
{
color
:
DataTypes
.
ENUM
([
"red"
,
"green"
,
"blue"
])})
Article
.
hasMany
(
Label
,
{
through
:
ArticleHasLabel
})
Label
.
hasMany
(
Article
,
{
through
:
ArticleHasLabel
})
return
this
.
sequelize
.
sync
({
force
:
true
}).
then
(
function
()
{
return
Article
.
create
().
then
(
function
(
article
)
{
return
Label
.
create
({
text
:
"cheap"
}).
then
(
function
(
label1
)
{
return
Label
.
create
({
text
:
"steal"
}).
then
(
function
(
label2
)
{
label2
.
ArticleHasLabel
=
{
color
:
"green"
}
return
article
.
setLabels
([
label1
,
label2
]).
then
(
function
()
{
label1
.
ArticleHasLabel
=
{
color
:
"red"
}
article
.
setLabels
([
label1
,
label2
]).
then
(
function
()
{
article
.
getLabels
().
then
(
function
(
labels
)
{
expect
(
labels
).
to
.
have
.
length
(
2
)
expect
(
labels
[
0
].
ArticleHasLabel
.
color
).
to
.
equal
(
"red"
)
expect
(
labels
[
1
].
ArticleHasLabel
.
color
).
to
.
equal
(
"green"
)
})
})
})
})
})
})
})
})
})
})
describe
(
'addAssociations'
,
function
()
{
describe
(
'addAssociations'
,
function
()
{
...
...
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