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 54655ab2
authored
May 08, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(model/destroy): fix model.destroy() where .sync() hasn't been called (closes #1730)
1 parent
11dba9ec
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
10 additions
and
10 deletions
lib/dialects/postgres/query-generator.js
lib/model.js
lib/query-interface.js
test/associations/has-many.test.js
lib/dialects/postgres/query-generator.js
View file @
54655ab
...
@@ -290,7 +290,7 @@ module.exports = (function() {
...
@@ -290,7 +290,7 @@ module.exports = (function() {
return
Utils
.
_
.
template
(
query
)(
replacements
)
return
Utils
.
_
.
template
(
query
)(
replacements
)
},
},
deleteQuery
:
function
(
tableName
,
where
,
options
,
factory
)
{
deleteQuery
:
function
(
tableName
,
where
,
options
,
model
)
{
options
=
options
||
{}
options
=
options
||
{}
tableName
=
Utils
.
removeTicks
(
this
.
quoteTable
(
tableName
),
'"'
)
tableName
=
Utils
.
removeTicks
(
this
.
quoteTable
(
tableName
),
'"'
)
...
@@ -305,8 +305,8 @@ module.exports = (function() {
...
@@ -305,8 +305,8 @@ module.exports = (function() {
primaryKeys
[
tableName
]
=
primaryKeys
[
tableName
]
||
[];
primaryKeys
[
tableName
]
=
primaryKeys
[
tableName
]
||
[];
if
(
!!
factory
&&
primaryKeys
[
tableName
].
length
<
1
)
{
if
(
!!
model
&&
primaryKeys
[
tableName
].
length
<
1
)
{
primaryKeys
[
tableName
]
=
Object
.
keys
(
factory
.
primaryKeys
)
primaryKeys
[
tableName
]
=
Object
.
keys
(
model
.
primaryKeys
)
}
}
var
query
=
"DELETE FROM <%= table %> WHERE <%= primaryKeys %> IN (SELECT <%= primaryKeysSelection %> FROM <%= table %> WHERE <%= where %><%= limit %>)"
var
query
=
"DELETE FROM <%= table %> WHERE <%= primaryKeys %> IN (SELECT <%= primaryKeysSelection %> FROM <%= table %> WHERE <%= where %><%= limit %>)"
...
...
lib/model.js
View file @
54655ab
...
@@ -1278,10 +1278,10 @@ module.exports = (function() {
...
@@ -1278,10 +1278,10 @@ module.exports = (function() {
var
attrValueHash
=
{}
var
attrValueHash
=
{}
attrValueHash
[
self
.
_timestampAttributes
.
deletedAt
]
=
Utils
.
now
()
attrValueHash
[
self
.
_timestampAttributes
.
deletedAt
]
=
Utils
.
now
()
query
=
'bulkUpdate'
query
=
'bulkUpdate'
args
=
[
self
.
getTableName
(),
attrValueHash
,
where
]
args
=
[
self
.
getTableName
(),
attrValueHash
,
where
,
self
]
}
else
{
}
else
{
query
=
'bulkDelete'
query
=
'bulkDelete'
args
=
[
self
.
getTableName
(),
where
,
options
]
args
=
[
self
.
getTableName
(),
where
,
options
,
self
]
}
}
var
runQuery
=
function
(
err
,
records
)
{
var
runQuery
=
function
(
err
,
records
)
{
...
...
lib/query-interface.js
View file @
54655ab
...
@@ -565,8 +565,8 @@ module.exports = (function() {
...
@@ -565,8 +565,8 @@ module.exports = (function() {
});
});
}
}
QueryInterface
.
prototype
.
bulkDelete
=
function
(
tableName
,
identifier
,
options
)
{
QueryInterface
.
prototype
.
bulkDelete
=
function
(
tableName
,
identifier
,
options
,
model
)
{
var
sql
=
this
.
QueryGenerator
.
deleteQuery
(
tableName
,
identifier
,
Utils
.
_
.
defaults
(
options
||
{},
{
limit
:
null
}))
var
sql
=
this
.
QueryGenerator
.
deleteQuery
(
tableName
,
identifier
,
Utils
.
_
.
defaults
(
options
||
{},
{
limit
:
null
})
,
model
)
return
this
.
queryAndEmit
([
sql
,
null
,
options
],
'bulkDelete'
,
options
)
return
this
.
queryAndEmit
([
sql
,
null
,
options
],
'bulkDelete'
,
options
)
}
}
...
...
test/associations/has-many.test.js
View file @
54655ab
...
@@ -1121,7 +1121,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
...
@@ -1121,7 +1121,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
})
})
})
})
describe
(
'
no run
sync'
,
function
()
{
describe
(
'
without
sync'
,
function
()
{
beforeEach
(
function
(
done
)
{
beforeEach
(
function
(
done
)
{
var
self
=
this
var
self
=
this
...
@@ -1139,8 +1139,8 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
...
@@ -1139,8 +1139,8 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
var
self
=
this
;
var
self
=
this
;
this
.
UsersTasks
=
this
.
sequelize
.
define
(
'UsersTasks'
,
{},
{
tableName
:
'users_tasks'
});
this
.
UsersTasks
=
this
.
sequelize
.
define
(
'UsersTasks'
,
{},
{
tableName
:
'users_tasks'
});
self
.
User
.
hasMany
(
self
.
Task
,
{
joinTableName
:
this
.
UsersTasks
})
self
.
User
.
hasMany
(
self
.
Task
,
{
through
:
this
.
UsersTasks
})
self
.
Task
.
hasMany
(
self
.
User
,
{
joinTableName
:
this
.
UsersTasks
})
self
.
Task
.
hasMany
(
self
.
User
,
{
through
:
this
.
UsersTasks
})
expect
(
Object
.
keys
(
self
.
UsersTasks
.
primaryKeys
)).
to
.
deep
.
equal
([
'TaskId'
,
'UserId'
])
expect
(
Object
.
keys
(
self
.
UsersTasks
.
primaryKeys
)).
to
.
deep
.
equal
([
'TaskId'
,
'UserId'
])
...
...
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