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 a2b24001
authored
Mar 08, 2014
by
Jan Aagaard Meier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed useConstraints to constraints
1 parent
1091f202
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
13 additions
and
13 deletions
lib/associations/belongs-to.js
lib/associations/has-many.js
lib/associations/has-one.js
test/associations/belongs-to.test.js
test/associations/has-many.test.js
test/associations/has-one.test.js
lib/associations/belongs-to.js
View file @
a2b2400
...
...
@@ -44,7 +44,7 @@ module.exports = (function() {
var
newAttributes
=
{}
newAttributes
[
this
.
identifier
]
=
{
type
:
this
.
options
.
keyType
||
this
.
target
.
rawAttributes
[
this
.
targetIdentifier
].
type
}
if
(
this
.
options
.
useC
onstraints
!==
false
)
{
if
(
this
.
options
.
c
onstraints
!==
false
)
{
this
.
options
.
onDelete
=
this
.
options
.
onDelete
||
'SET NULL'
this
.
options
.
onUpdate
=
this
.
options
.
onUpdate
||
'CASCADE'
}
...
...
lib/associations/has-many.js
View file @
a2b2400
...
...
@@ -180,13 +180,13 @@ module.exports = (function() {
,
sourceAttribute
=
{
type
:
sourceKeyType
}
,
targetAttribute
=
{
type
:
targetKeyType
}
if
(
this
.
options
.
useC
onstraints
!==
false
)
{
if
(
this
.
options
.
c
onstraints
!==
false
)
{
sourceAttribute
.
references
=
this
.
source
.
getTableName
()
sourceAttribute
.
referencesKey
=
this
.
source
.
primaryKeyAttribute
sourceAttribute
.
onDelete
=
this
.
options
.
onDelete
||
'CASCADE'
sourceAttribute
.
onUpdate
=
this
.
options
.
onUpdate
||
'CASCADE'
}
if
(
this
.
targetAssociation
.
options
.
useC
onstraints
!==
false
)
{
if
(
this
.
targetAssociation
.
options
.
c
onstraints
!==
false
)
{
targetAttribute
.
references
=
this
.
target
.
getTableName
()
targetAttribute
.
referencesKey
=
this
.
target
.
primaryKeyAttribute
targetAttribute
.
onDelete
=
this
.
targetAssociation
.
options
.
onDelete
||
'CASCADE'
...
...
@@ -210,7 +210,7 @@ module.exports = (function() {
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
.
identifier
]
=
{
type
:
this
.
options
.
keyType
||
this
.
target
.
rawAttributes
[
this
.
target
.
primaryKeyAttribute
].
type
}
if
(
this
.
options
.
useC
onstraints
!==
false
)
{
if
(
this
.
options
.
c
onstraints
!==
false
)
{
constraintOptions
.
onDelete
=
constraintOptions
.
onDelete
||
'SET NULL'
constraintOptions
.
onUpdate
=
constraintOptions
.
onUpdate
||
'CASCADE'
}
...
...
lib/associations/has-one.js
View file @
a2b2400
...
...
@@ -46,7 +46,7 @@ module.exports = (function() {
newAttributes
[
this
.
identifier
]
=
{
type
:
this
.
options
.
keyType
||
keyType
}
Utils
.
_
.
defaults
(
this
.
target
.
rawAttributes
,
newAttributes
)
if
(
this
.
options
.
useC
onstraints
!==
false
)
{
if
(
this
.
options
.
c
onstraints
!==
false
)
{
this
.
options
.
onDelete
=
this
.
options
.
onDelete
||
'SET NULL'
this
.
options
.
onUpdate
=
this
.
options
.
onUpdate
||
'CASCADE'
}
...
...
test/associations/belongs-to.test.js
View file @
a2b2400
...
...
@@ -265,7 +265,7 @@ describe(Support.getTestDialectTeaser("BelongsTo"), function() {
var
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
,
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
Task
.
belongsTo
(
User
,
{
useC
onstraints
:
false
})
Task
.
belongsTo
(
User
,
{
c
onstraints
:
false
})
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
}).
success
(
function
(
user
)
{
...
...
@@ -425,7 +425,7 @@ describe(Support.getTestDialectTeaser("BelongsTo"), function() {
var
tableName
=
'TaskXYZ_'
+
dataType
.
toString
()
Tasks
[
dataType
]
=
self
.
sequelize
.
define
(
tableName
,
{
title
:
DataTypes
.
STRING
})
Tasks
[
dataType
].
belongsTo
(
User
,
{
foreignKey
:
'userId'
,
keyType
:
dataType
,
useC
onstraints
:
false
})
Tasks
[
dataType
].
belongsTo
(
User
,
{
foreignKey
:
'userId'
,
keyType
:
dataType
,
c
onstraints
:
false
})
})
self
.
sequelize
.
sync
({
force
:
true
})
...
...
test/associations/has-many.test.js
View file @
a2b2400
...
...
@@ -1377,7 +1377,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
var
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
DataTypes
.
STRING
})
,
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
DataTypes
.
STRING
})
User
.
hasMany
(
Task
,
{
useC
onstraints
:
false
})
User
.
hasMany
(
Task
,
{
c
onstraints
:
false
})
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
}).
success
(
function
(
user
)
{
...
...
@@ -1623,8 +1623,8 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
var
_done
=
_
.
after
(
2
,
done
)
,
self
=
this
self
.
User
.
hasMany
(
self
.
Task
,
{
useC
onstraints
:
false
})
self
.
Task
.
hasMany
(
self
.
User
,
{
useC
onstraints
:
false
})
self
.
User
.
hasMany
(
self
.
Task
,
{
c
onstraints
:
false
})
self
.
Task
.
hasMany
(
self
.
User
,
{
c
onstraints
:
false
})
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
self
.
User
.
create
({
id
:
67
,
username
:
'foo'
}).
success
(
function
(
user
)
{
...
...
@@ -1670,7 +1670,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
var
tableName
=
'TaskXYZ_'
+
dataType
.
toString
()
Tasks
[
dataType
]
=
self
.
sequelize
.
define
(
tableName
,
{
title
:
DataTypes
.
STRING
})
User
.
hasMany
(
Tasks
[
dataType
],
{
foreignKey
:
'userId'
,
keyType
:
dataType
,
useC
onstraints
:
false
})
User
.
hasMany
(
Tasks
[
dataType
],
{
foreignKey
:
'userId'
,
keyType
:
dataType
,
c
onstraints
:
false
})
Tasks
[
dataType
].
sync
({
force
:
true
}).
success
(
function
()
{
expect
(
Tasks
[
dataType
].
rawAttributes
.
userId
.
type
.
toString
())
...
...
test/associations/has-one.test.js
View file @
a2b2400
...
...
@@ -240,7 +240,7 @@ describe(Support.getTestDialectTeaser("HasOne"), function() {
var
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
,
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
User
.
hasOne
(
Task
,
{
useC
onstraints
:
false
})
User
.
hasOne
(
Task
,
{
c
onstraints
:
false
})
User
.
sync
({
force
:
true
}).
success
(
function
()
{
Task
.
sync
({
force
:
true
}).
success
(
function
()
{
...
...
@@ -411,7 +411,7 @@ describe(Support.getTestDialectTeaser("HasOne"), function() {
var
tableName
=
'TaskXYZ_'
+
dataType
.
toString
()
Tasks
[
dataType
]
=
self
.
sequelize
.
define
(
tableName
,
{
title
:
Sequelize
.
STRING
})
User
.
hasOne
(
Tasks
[
dataType
],
{
foreignKey
:
'userId'
,
keyType
:
dataType
,
useC
onstraints
:
false
})
User
.
hasOne
(
Tasks
[
dataType
],
{
foreignKey
:
'userId'
,
keyType
:
dataType
,
c
onstraints
:
false
})
Tasks
[
dataType
].
sync
({
force
:
true
}).
success
(
function
()
{
expect
(
Tasks
[
dataType
].
rawAttributes
.
userId
.
type
.
toString
())
...
...
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