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 5f46ef87
authored
Apr 20, 2014
by
Jan Scheurer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix foreign key type for has-many associations, retrofits
71068a11
1 parent
140fa167
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
1 deletions
lib/associations/has-many.js
test/associations/has-many.test.js
lib/associations/has-many.js
View file @
5f46ef8
...
@@ -190,7 +190,10 @@ module.exports = (function() {
...
@@ -190,7 +190,10 @@ module.exports = (function() {
}
}
}
else
{
}
else
{
var
newAttributes
=
{}
var
newAttributes
=
{}
newAttributes
[
this
.
identifier
]
=
{
type
:
this
.
options
.
keyType
||
DataTypes
.
INTEGER
}
,
sourceKeys
=
Object
.
keys
(
this
.
source
.
primaryKeys
)
,
keyType
=
((
this
.
source
.
hasPrimaryKeys
&&
sourceKeys
.
length
===
1
)
?
this
.
source
.
rawAttributes
[
sourceKeys
[
0
]].
type
:
DataTypes
.
INTEGER
)
newAttributes
[
this
.
identifier
]
=
{
type
:
this
.
options
.
keyType
||
keyType
}
Helpers
.
addForeignKeyConstraints
(
newAttributes
[
this
.
identifier
],
this
.
source
,
this
.
target
,
this
.
options
)
Helpers
.
addForeignKeyConstraints
(
newAttributes
[
this
.
identifier
],
this
.
source
,
this
.
target
,
this
.
options
)
Utils
.
_
.
defaults
(
this
.
target
.
rawAttributes
,
newAttributes
)
Utils
.
_
.
defaults
(
this
.
target
.
rawAttributes
,
newAttributes
)
}
}
...
...
test/associations/has-many.test.js
View file @
5f46ef8
...
@@ -1509,5 +1509,24 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
...
@@ -1509,5 +1509,24 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
})
})
})
})
})
})
it
(
'infers the keyType if none provided'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
id
:
{
type
:
DataTypes
.
STRING
,
primaryKey
:
true
},
username
:
DataTypes
.
STRING
})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
DataTypes
.
STRING
})
User
.
hasMany
(
Task
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
expect
(
Task
.
rawAttributes
.
UserId
.
type
.
toString
())
.
to
.
equal
(
DataTypes
.
STRING
.
toString
())
done
()
})
})
})
})
})
})
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