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 6fda1564
authored
Sep 03, 2013
by
Jan Aagaard Meier
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #881 from durango/destroyfix
Fixes a bug with .destroy() on a DAO record
2 parents
1c16932d
84603352
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
2 deletions
lib/dialects/postgres/query-generator.js
lib/query-interface.js
test/dao.test.js
lib/dialects/postgres/query-generator.js
View file @
6fda156
...
@@ -402,7 +402,7 @@ module.exports = (function() {
...
@@ -402,7 +402,7 @@ module.exports = (function() {
return
Utils
.
_
.
template
(
query
)(
replacements
)
return
Utils
.
_
.
template
(
query
)(
replacements
)
},
},
deleteQuery
:
function
(
tableName
,
where
,
options
)
{
deleteQuery
:
function
(
tableName
,
where
,
options
,
factory
)
{
options
=
options
||
{}
options
=
options
||
{}
if
(
options
.
truncate
===
true
)
{
if
(
options
.
truncate
===
true
)
{
...
@@ -415,6 +415,10 @@ module.exports = (function() {
...
@@ -415,6 +415,10 @@ module.exports = (function() {
primaryKeys
[
tableName
]
=
primaryKeys
[
tableName
]
||
[];
primaryKeys
[
tableName
]
=
primaryKeys
[
tableName
]
||
[];
if
(
!!
factory
&&
primaryKeys
[
tableName
].
length
<
1
)
{
primaryKeys
[
tableName
]
=
Object
.
keys
(
factory
.
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 %>)"
var
pks
;
var
pks
;
...
...
lib/query-interface.js
View file @
6fda156
...
@@ -481,7 +481,7 @@ module.exports = (function() {
...
@@ -481,7 +481,7 @@ module.exports = (function() {
QueryInterface
.
prototype
.
delete
=
function
(
dao
,
tableName
,
identifier
)
{
QueryInterface
.
prototype
.
delete
=
function
(
dao
,
tableName
,
identifier
)
{
var
self
=
this
var
self
=
this
,
restrict
=
false
,
restrict
=
false
,
sql
=
self
.
QueryGenerator
.
deleteQuery
(
tableName
,
identifier
)
,
sql
=
self
.
QueryGenerator
.
deleteQuery
(
tableName
,
identifier
,
null
,
dao
.
daoFactory
)
// Check for a restrict field
// Check for a restrict field
if
(
!!
dao
.
daoFactory
&&
!!
dao
.
daoFactory
.
associations
)
{
if
(
!!
dao
.
daoFactory
&&
!!
dao
.
daoFactory
.
associations
)
{
...
...
test/dao.test.js
View file @
6fda156
...
@@ -1000,6 +1000,34 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
...
@@ -1000,6 +1000,34 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
})
})
})
})
it
(
'destroys a record with a primary key of something other than id'
,
function
(
done
)
{
var
UserDestroy
=
this
.
sequelize
.
define
(
'UserDestroy'
,
{
newId
:
{
type
:
DataTypes
.
STRING
,
primaryKey
:
true
},
email
:
DataTypes
.
STRING
})
UserDestroy
.
sync
().
success
(
function
()
{
UserDestroy
.
create
({
newId
:
'123ABC'
,
email
:
'hello'
}).
success
(
function
()
{
UserDestroy
.
find
({
where
:
{
email
:
'hello'
}}).
success
(
function
(
user
)
{
user
.
destroy
().
on
(
'sql'
,
function
(
sql
)
{
if
(
dialect
===
"postgres"
||
dialect
===
"postgres-native"
)
{
expect
(
sql
).
to
.
equal
(
'DELETE FROM "UserDestroys" WHERE "newId" IN (SELECT "newId" FROM "UserDestroys" WHERE "newId"=\'123ABC\' LIMIT 1)'
)
}
else
if
(
dialect
===
"mysql"
)
{
expect
(
sql
).
to
.
equal
(
"DELETE FROM `UserDestroys` WHERE `newId`='123ABC' LIMIT 1"
)
}
else
{
expect
(
sql
).
to
.
equal
(
"DELETE FROM `UserDestroys` WHERE `newId`='123ABC'"
)
}
done
()
})
})
})
})
})
it
(
"sets deletedAt property to a specific date when deleting an instance"
,
function
(
done
)
{
it
(
"sets deletedAt property to a specific date when deleting an instance"
,
function
(
done
)
{
var
self
=
this
var
self
=
this
this
.
ParanoidUser
.
create
({
username
:
'fnord'
}).
success
(
function
()
{
this
.
ParanoidUser
.
create
({
username
:
'fnord'
}).
success
(
function
()
{
...
...
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