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 b6c2e421
authored
Jul 14, 2018
by
Sushant
Committed by
GitHub
Jul 14, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(hasOne.sourceKey): setup sourceKeyAttribute for joins (#9658)
1 parent
c90c8d5c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
6 additions
and
8 deletions
lib/associations/has-many.js
lib/associations/has-one.js
package.json
test/integration/associations/has-one.test.js
lib/associations/has-many.js
View file @
b6c2e42
...
@@ -80,7 +80,6 @@ class HasMany extends Association {
...
@@ -80,7 +80,6 @@ class HasMany extends Association {
* Source key setup
* Source key setup
*/
*/
this
.
sourceKey
=
this
.
options
.
sourceKey
||
this
.
source
.
primaryKeyAttribute
;
this
.
sourceKey
=
this
.
options
.
sourceKey
||
this
.
source
.
primaryKeyAttribute
;
this
.
sourceIdentifier
=
this
.
sourceKey
;
if
(
this
.
source
.
rawAttributes
[
this
.
sourceKey
])
{
if
(
this
.
source
.
rawAttributes
[
this
.
sourceKey
])
{
this
.
sourceKeyAttribute
=
this
.
sourceKey
;
this
.
sourceKeyAttribute
=
this
.
sourceKey
;
...
...
lib/associations/has-one.js
View file @
b6c2e42
...
@@ -55,10 +55,9 @@ class HasOne extends Association {
...
@@ -55,10 +55,9 @@ class HasOne extends Association {
throw
new
Error
(
`Unknown attribute "
${
this
.
options
.
sourceKey
}
" passed as sourceKey, define this attribute on model "
${
this
.
source
.
name
}
" first`
);
throw
new
Error
(
`Unknown attribute "
${
this
.
options
.
sourceKey
}
" passed as sourceKey, define this attribute on model "
${
this
.
source
.
name
}
" first`
);
}
}
this
.
sourceKey
=
this
.
options
.
sourceKey
||
this
.
source
.
primaryKeyAttribute
;
this
.
sourceKey
=
this
.
sourceKeyAttribute
=
this
.
options
.
sourceKey
||
this
.
source
.
primaryKeyAttribute
;
this
.
sourceKeyField
=
this
.
source
.
rawAttributes
[
this
.
sourceKey
].
field
||
this
.
sourceKey
;
this
.
sourceKeyField
=
this
.
source
.
rawAttributes
[
this
.
sourceKey
].
field
||
this
.
sourceKey
;
this
.
sourceKeyIsPrimary
=
this
.
sourceKey
===
this
.
source
.
primaryKeyAttribute
;
this
.
sourceKeyIsPrimary
=
this
.
sourceKey
===
this
.
source
.
primaryKeyAttribute
;
this
.
sourceIdentifier
=
this
.
sourceKey
;
this
.
associationAccessor
=
this
.
as
;
this
.
associationAccessor
=
this
.
as
;
this
.
options
.
useHooks
=
options
.
useHooks
;
this
.
options
.
useHooks
=
options
.
useHooks
;
...
@@ -218,7 +217,7 @@ class HasOne extends Association {
...
@@ -218,7 +217,7 @@ class HasOne extends Association {
}
}
_
.
assign
(
associatedInstance
,
this
.
scope
);
_
.
assign
(
associatedInstance
,
this
.
scope
);
associatedInstance
.
set
(
this
.
foreignKey
,
sourceInstance
.
get
(
this
.
source
Identifier
));
associatedInstance
.
set
(
this
.
foreignKey
,
sourceInstance
.
get
(
this
.
source
KeyAttribute
));
return
associatedInstance
.
save
(
options
);
return
associatedInstance
.
save
(
options
);
}
}
...
@@ -250,7 +249,7 @@ class HasOne extends Association {
...
@@ -250,7 +249,7 @@ class HasOne extends Association {
}
}
}
}
values
[
this
.
foreignKey
]
=
sourceInstance
.
get
(
this
.
source
Identifier
);
values
[
this
.
foreignKey
]
=
sourceInstance
.
get
(
this
.
source
KeyAttribute
);
if
(
options
.
fields
)
{
if
(
options
.
fields
)
{
options
.
fields
.
push
(
this
.
foreignKey
);
options
.
fields
.
push
(
this
.
foreignKey
);
}
}
...
...
package.json
View file @
b6c2e42
...
@@ -65,7 +65,7 @@
...
@@ -65,7 +65,7 @@
"semantic-release"
:
"^15.x"
,
"semantic-release"
:
"^15.x"
,
"sinon"
:
"^6.0.0"
,
"sinon"
:
"^6.0.0"
,
"sinon-chai"
:
"^3.2.0"
,
"sinon-chai"
:
"^3.2.0"
,
"sqlite3"
:
"^4.
x
"
,
"sqlite3"
:
"^4.
0.1
"
,
"tedious"
:
"^2.x"
,
"tedious"
:
"^2.x"
,
"uuid-validate"
:
"^0.0.3"
,
"uuid-validate"
:
"^0.0.3"
,
"validate-commit-msg"
:
"^2.12.2"
"validate-commit-msg"
:
"^2.12.2"
...
...
test/integration/associations/has-one.test.js
View file @
b6c2e42
...
@@ -668,8 +668,8 @@ describe(Support.getTestDialectTeaser('HasOne'), () => {
...
@@ -668,8 +668,8 @@ describe(Support.getTestDialectTeaser('HasOne'), () => {
it
(
'should support a non-primary key as the association column on a target with custom primary key'
,
function
()
{
it
(
'should support a non-primary key as the association column on a target with custom primary key'
,
function
()
{
const
User
=
this
.
sequelize
.
define
(
'User'
,
{
const
User
=
this
.
sequelize
.
define
(
'User'
,
{
user_name
:
{
user_name
:
{
type
:
Sequelize
.
STRING
,
unique
:
true
,
primaryKey
:
true
type
:
Sequelize
.
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