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 1b222915
authored
Sep 04, 2013
by
Domas Lapinskas
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'upstream/master'
2 parents
fb4345c3
85838c2e
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
65 additions
and
6 deletions
lib/dao-factory.js
lib/dialects/postgres/query-generator.js
lib/query-interface.js
test/dao-factory.test.js
test/dao.test.js
lib/dao-factory.js
View file @
1b22291
...
...
@@ -324,7 +324,8 @@ module.exports = (function() {
DAOFactory
.
prototype
.
findAll
=
function
(
options
,
queryOptions
)
{
var
hasJoin
=
false
var
options
=
Utils
.
_
.
clone
(
options
)
options
=
optClone
(
options
)
if
(
typeof
options
===
'object'
)
{
if
(
options
.
hasOwnProperty
(
'include'
))
{
...
...
@@ -378,6 +379,7 @@ module.exports = (function() {
var
primaryKeys
=
this
.
primaryKeys
,
keys
=
Object
.
keys
(
primaryKeys
)
,
keysLength
=
keys
.
length
options
=
optClone
(
options
)
// options is not a hash but an id
if
(
typeof
options
===
'number'
)
{
...
...
@@ -804,6 +806,13 @@ module.exports = (function() {
return
attributes
}
var
optClone
=
function
(
options
)
{
return
Utils
.
_
.
cloneDeep
(
options
,
function
(
elem
)
{
// The DAOFactories used for include are pass by ref, so don't clone them. Otherwise return undefined, meaning, 'handle this lodash'
return
elem
instanceof
DAOFactory
?
elem
:
undefined
})
}
Utils
.
_
.
extend
(
DAOFactory
.
prototype
,
require
(
"./associations/mixin"
))
return
DAOFactory
...
...
lib/dialects/postgres/query-generator.js
View file @
1b22291
...
...
@@ -402,7 +402,7 @@ module.exports = (function() {
return
Utils
.
_
.
template
(
query
)(
replacements
)
},
deleteQuery
:
function
(
tableName
,
where
,
options
)
{
deleteQuery
:
function
(
tableName
,
where
,
options
,
factory
)
{
options
=
options
||
{}
if
(
options
.
truncate
===
true
)
{
...
...
@@ -415,6 +415,10 @@ module.exports = (function() {
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
pks
;
...
...
lib/query-interface.js
View file @
1b22291
...
...
@@ -481,7 +481,7 @@ module.exports = (function() {
QueryInterface
.
prototype
.
delete
=
function
(
dao
,
tableName
,
identifier
)
{
var
self
=
this
,
restrict
=
false
,
sql
=
self
.
QueryGenerator
.
deleteQuery
(
tableName
,
identifier
)
,
sql
=
self
.
QueryGenerator
.
deleteQuery
(
tableName
,
identifier
,
null
,
dao
.
daoFactory
)
// Check for a restrict field
if
(
!!
dao
.
daoFactory
&&
!!
dao
.
daoFactory
.
associations
)
{
...
...
test/dao-factory.test.js
View file @
1b22291
...
...
@@ -1426,14 +1426,14 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
var
self
=
this
this
.
User
.
create
({
username
:
'barfooz'
}).
success
(
function
(
user
)
{
self
.
UserPrimary
=
self
.
sequelize
.
define
(
'UserPrimary'
,
{
special
K
ey
:
{
special
k
ey
:
{
type
:
DataTypes
.
STRING
,
primaryKey
:
true
}
})
self
.
UserPrimary
.
sync
({
force
:
true
}).
success
(
function
()
{
self
.
UserPrimary
.
create
({
special
K
ey
:
'a string'
}).
success
(
function
()
{
self
.
UserPrimary
.
create
({
special
k
ey
:
'a string'
}).
success
(
function
()
{
self
.
user
=
user
done
()
})
...
...
@@ -1441,9 +1441,18 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
it
(
'does not modify the passed arguments'
,
function
(
done
)
{
var
options
=
{
where
:
[
'specialkey = ?'
,
'awesome'
]}
this
.
UserPrimary
.
find
(
options
).
success
(
function
(
user
)
{
expect
(
options
).
to
.
deep
.
equal
({
where
:
[
'specialkey = ?'
,
'awesome'
]})
done
()
})
})
it
(
'doesn\'t throw an error when entering in a non integer value for a specified primary field'
,
function
(
done
)
{
this
.
UserPrimary
.
find
(
'a string'
).
success
(
function
(
user
)
{
expect
(
user
.
special
K
ey
).
to
.
equal
(
'a string'
)
expect
(
user
.
special
k
ey
).
to
.
equal
(
'a string'
)
done
()
})
})
...
...
@@ -2458,6 +2467,15 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
it
(
'does not modify the passed arguments'
,
function
(
done
)
{
var
options
=
{
where
:
[
'username = ?'
,
'awesome'
]}
this
.
User
.
findAll
(
options
).
success
(
function
(
user
)
{
expect
(
options
).
to
.
deep
.
equal
({
where
:
[
'username = ?'
,
'awesome'
]})
done
()
})
})
it
(
"finds all users matching the passed conditions"
,
function
(
done
)
{
this
.
User
.
findAll
({
where
:
"id != "
+
this
.
users
[
1
].
id
}).
success
(
function
(
users
)
{
expect
(
users
.
length
).
to
.
equal
(
1
)
...
...
test/dao.test.js
View file @
1b22291
...
...
@@ -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
)
{
var
self
=
this
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