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 55c96079
authored
Nov 26, 2015
by
Sebastian Wilzbach
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
don't overwrite options.foreignKey in associations
1 parent
f482790b
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
66 additions
and
5 deletions
changelog.md
lib/associations/belongs-to-many.js
lib/associations/belongs-to.js
lib/associations/has-many.js
lib/associations/has-one.js
test/unit/associations/dont-modify-options.test.js
changelog.md
View file @
55c9607
# Next
-
[
FIXED
]
Don't overwrite options.foreignKey in associations
[
#4927
](
https://github.com/sequelize/sequelize/pull/4927
)
# 3.14.1
-
[
FIXED
]
Issue with transaction options leaking and certain queries running outside of the transaction connection.
...
...
lib/associations/belongs-to-many.js
View file @
55c9607
...
...
@@ -323,8 +323,8 @@ BelongsToMany.prototype.injectAttributes = function() {
,
targetKey
=
this
.
target
.
rawAttributes
[
this
.
target
.
primaryKeyAttribute
]
,
targetKeyType
=
targetKey
.
type
,
targetKeyField
=
targetKey
.
field
||
this
.
target
.
primaryKeyAttribute
,
sourceAttribute
=
_
.
defaults
(
this
.
foreignKeyAttribute
,
{
type
:
sourceKeyType
})
,
targetAttribute
=
_
.
defaults
(
this
.
otherKeyAttribute
,
{
type
:
targetKeyType
});
,
sourceAttribute
=
_
.
defaults
(
{},
this
.
foreignKeyAttribute
,
{
type
:
sourceKeyType
})
,
targetAttribute
=
_
.
defaults
(
{},
this
.
otherKeyAttribute
,
{
type
:
targetKeyType
});
if
(
this
.
primaryKeyDeleted
===
true
)
{
targetAttribute
.
primaryKey
=
sourceAttribute
.
primaryKey
=
true
;
...
...
lib/associations/belongs-to.js
View file @
55c9607
...
...
@@ -109,7 +109,7 @@ util.inherits(BelongsTo, Association);
BelongsTo
.
prototype
.
injectAttributes
=
function
()
{
var
newAttributes
=
{};
newAttributes
[
this
.
foreignKey
]
=
_
.
defaults
(
this
.
foreignKeyAttribute
,
{
newAttributes
[
this
.
foreignKey
]
=
_
.
defaults
(
{},
this
.
foreignKeyAttribute
,
{
type
:
this
.
options
.
keyType
||
this
.
target
.
rawAttributes
[
this
.
targetKey
].
type
,
allowNull
:
true
});
...
...
lib/associations/has-many.js
View file @
55c9607
...
...
@@ -202,7 +202,7 @@ util.inherits(HasMany, Association);
HasMany
.
prototype
.
injectAttributes
=
function
()
{
var
newAttributes
=
{};
var
constraintOptions
=
_
.
clone
(
this
.
options
);
// Create a new options object for use with addForeignKeyConstraints, to avoid polluting this.options in case it is later used for a n:m
newAttributes
[
this
.
foreignKey
]
=
_
.
defaults
(
this
.
foreignKeyAttribute
,
{
newAttributes
[
this
.
foreignKey
]
=
_
.
defaults
(
{},
this
.
foreignKeyAttribute
,
{
type
:
this
.
options
.
keyType
||
this
.
source
.
rawAttributes
[
this
.
source
.
primaryKeyAttribute
].
type
,
allowNull
:
true
});
...
...
lib/associations/has-one.js
View file @
55c9607
...
...
@@ -103,7 +103,7 @@ HasOne.prototype.injectAttributes = function() {
var
newAttributes
=
{}
,
keyType
=
this
.
source
.
rawAttributes
[
this
.
source
.
primaryKeyAttribute
].
type
;
newAttributes
[
this
.
foreignKey
]
=
_
.
defaults
(
this
.
foreignKeyAttribute
,
{
newAttributes
[
this
.
foreignKey
]
=
_
.
defaults
(
{},
this
.
foreignKeyAttribute
,
{
type
:
this
.
options
.
keyType
||
keyType
,
allowNull
:
true
});
...
...
test/unit/associations/dont-modify-options.test.js
0 → 100644
View file @
55c9607
'use strict'
;
/* jshint -W030 */
var
chai
=
require
(
'chai'
)
,
expect
=
chai
.
expect
,
Support
=
require
(
__dirname
+
'/../support'
)
,
DataTypes
=
require
(
__dirname
+
'/../../../lib/data-types'
)
,
Sequelize
=
require
(
'../../../index'
);
describe
(
Support
.
getTestDialectTeaser
(
'associations'
),
function
()
{
describe
(
'Test options.foreignKey'
,
function
()
{
beforeEach
(
function
()
{
this
.
A
=
this
.
sequelize
.
define
(
'A'
,
{
id
:
{
type
:
DataTypes
.
CHAR
(
20
),
primaryKey
:
true
}
});
this
.
B
=
this
.
sequelize
.
define
(
'B'
,
{
id
:
{
type
:
Sequelize
.
CHAR
(
20
),
primaryKey
:
true
}
});
this
.
C
=
this
.
sequelize
.
define
(
'C'
,
{});
});
it
(
'should not be overwritten for belongsTo'
,
function
(){
var
self
=
this
;
var
reqValidForeignKey
=
{
foreignKey
:
{
allowNull
:
false
}};
self
.
A
.
belongsTo
(
self
.
B
,
reqValidForeignKey
);
self
.
A
.
belongsTo
(
self
.
C
,
reqValidForeignKey
);
expect
(
self
.
A
.
attributes
.
CId
.
type
).
to
.
deep
.
equal
(
self
.
C
.
attributes
.
id
.
type
);
});
it
(
'should not be overwritten for belongsToMany'
,
function
(){
var
self
=
this
;
var
reqValidForeignKey
=
{
foreignKey
:
{
allowNull
:
false
},
through
:
'ABBridge'
};
self
.
B
.
belongsToMany
(
self
.
A
,
reqValidForeignKey
);
self
.
A
.
belongsTo
(
self
.
C
,
reqValidForeignKey
);
expect
(
self
.
A
.
attributes
.
CId
.
type
).
to
.
deep
.
equal
(
self
.
C
.
attributes
.
id
.
type
);
});
it
(
'should not be overwritten for hasOne'
,
function
(){
var
self
=
this
;
var
reqValidForeignKey
=
{
foreignKey
:
{
allowNull
:
false
}};
self
.
B
.
hasOne
(
self
.
A
,
reqValidForeignKey
);
self
.
A
.
belongsTo
(
self
.
C
,
reqValidForeignKey
);
expect
(
self
.
A
.
attributes
.
CId
.
type
).
to
.
deep
.
equal
(
self
.
C
.
attributes
.
id
.
type
);
});
it
(
'should not be overwritten for hasMany'
,
function
(){
var
self
=
this
;
var
reqValidForeignKey
=
{
foreignKey
:
{
allowNull
:
false
}};
self
.
B
.
hasMany
(
self
.
A
,
reqValidForeignKey
);
self
.
A
.
belongsTo
(
self
.
C
,
reqValidForeignKey
);
expect
(
self
.
A
.
attributes
.
CId
.
type
).
to
.
deep
.
equal
(
self
.
C
.
attributes
.
id
.
type
);
});
});
});
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