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 c5ef4740
authored
Sep 11, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:sequelize/sequelize
2 parents
ec4e3fab
2dbdbc47
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
100 additions
and
40 deletions
lib/model.js
test/dao-factory.test.js
test/dao.test.js
lib/model.js
View file @
c5ef474
...
@@ -1613,7 +1613,7 @@ module.exports = (function() {
...
@@ -1613,7 +1613,7 @@ module.exports = (function() {
// private
// private
var
paranoidClause
=
function
(
options
)
{
var
paranoidClause
=
function
(
options
)
{
if
(
!
this
.
options
.
timestamps
||
!
this
.
options
.
paranoid
||
options
.
paranoid
===
false
)
return
options
||
{};
if
(
!
this
.
options
.
timestamps
||
!
this
.
options
.
paranoid
||
options
.
paranoid
===
false
)
return
options
||
{};
options
=
options
||
{};
options
=
options
||
{};
...
@@ -1624,53 +1624,27 @@ module.exports = (function() {
...
@@ -1624,53 +1624,27 @@ module.exports = (function() {
// otherwise this code will never run on includes of a already conditionable where
// otherwise this code will never run on includes of a already conditionable where
if
(
options
.
include
&&
options
.
include
.
length
)
{
if
(
options
.
include
&&
options
.
include
.
length
)
{
options
.
include
.
forEach
(
function
(
include
)
{
options
.
include
.
forEach
(
function
(
include
)
{
if
(
typeof
include
===
'object'
&&
include
.
model
)
{
if
(
Utils
.
_
.
isPlainObject
(
include
)
&&
include
.
model
)
{
paranoidClause
.
call
(
include
.
model
,
include
);
paranoidClause
.
call
(
include
.
model
,
include
);
}
}
});
});
}
}
var
deletedAtCol
=
this
.
_timestampAttributes
.
deletedAt
var
deletedAtCol
=
this
.
_timestampAttributes
.
deletedAt
,
quoteIdentifiedDeletedAtCol
=
this
.
QueryInterface
.
quoteIdentifier
(
deletedAtCol
)
;
,
deletedAtObject
=
{}
;
// Don't overwrite our explicit deletedAt search value if we provide one
deletedAtObject
[
deletedAtCol
]
=
null
;
if
(
!!
options
.
where
[
deletedAtCol
])
{
return
options
;
}
if
(
this
.
name
||
this
.
tableName
)
{
quoteIdentifiedDeletedAtCol
=
this
.
QueryInterface
.
quoteIdentifier
(
this
.
name
||
this
.
tableName
)
+
'.'
+
quoteIdentifiedDeletedAtCol
;
}
if
(
typeof
options
.
where
===
'string'
)
{
// detect emptiness
options
.
where
+=
' AND '
+
quoteIdentifiedDeletedAtCol
+
' IS NULL '
;
if
(
}
Utils
.
_
.
isObject
(
options
.
where
)
&&
Object
.
keys
(
options
.
where
).
length
===
0
||
else
if
(
Array
.
isArray
(
options
.
where
))
{
(
Utils
.
_
.
isString
(
options
.
where
)
||
Utils
.
_
.
isArray
(
options
.
where
)
)
&&
options
.
where
.
length
===
0
// Need to check how the array is being used, as it could be an array
)
{
// of string-likes/Dates or an array with objects, hashes, or other
options
.
where
=
deletedAtObject
;
// complex data types
return
options
;
if
(
Utils
.
canTreatArrayAsAnd
(
options
.
where
))
{
// Don't overwrite our explicit deletedAt search value if we provide one
var
whereClause
=
this
.
QueryGenerator
.
getWhereConditions
(
options
.
where
,
this
.
getTableName
(),
this
,
options
);
if
(
whereClause
.
indexOf
(
deletedAtCol
)
!==
-
1
)
{
return
options
;
}
var
whereObj
=
{};
whereObj
[
quoteIdentifiedDeletedAtCol
]
=
null
;
options
.
where
.
push
(
whereObj
);
}
else
if
(
options
.
where
.
length
)
{
if
(
options
.
where
[
0
].
indexOf
(
deletedAtCol
)
!==
-
1
)
{
return
options
;
}
// Don't overwrite our explicit deletedAt search value if we provide one
options
.
where
[
0
]
+=
' AND '
+
quoteIdentifiedDeletedAtCol
+
' IS NULL '
;
}
else
{
options
.
where
[
0
]
=
quoteIdentifiedDeletedAtCol
+
' IS NULL '
;
}
}
else
{
options
.
where
[
deletedAtCol
]
=
null
;
}
}
options
.
where
=
this
.
sequelize
.
and
(
deletedAtObject
,
options
.
where
);
return
options
;
return
options
;
};
};
...
...
test/dao-factory.test.js
View file @
c5ef474
...
@@ -2250,12 +2250,13 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
...
@@ -2250,12 +2250,13 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
})
})
it
(
'should not overwrite a specified deletedAt'
,
function
(
done
)
{
it
(
'should not overwrite a specified deletedAt
by setting paranoid: false
'
,
function
(
done
)
{
var
tableName
=
''
var
tableName
=
''
if
(
this
.
User
.
name
)
{
if
(
this
.
User
.
name
)
{
tableName
=
this
.
sequelize
.
queryInterface
.
QueryGenerator
.
quoteIdentifier
(
this
.
User
.
name
)
+
'.'
tableName
=
this
.
sequelize
.
queryInterface
.
QueryGenerator
.
quoteIdentifier
(
this
.
User
.
name
)
+
'.'
}
}
this
.
User
.
findAll
({
this
.
User
.
findAll
({
paranoid
:
false
,
where
:
[
where
:
[
tableName
+
this
.
sequelize
.
queryInterface
.
QueryGenerator
.
quoteIdentifier
(
'deletedAt'
)
+
' IS NOT NULL '
tableName
+
this
.
sequelize
.
queryInterface
.
QueryGenerator
.
quoteIdentifier
(
'deletedAt'
)
+
' IS NOT NULL '
],
],
...
@@ -2274,8 +2275,9 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
...
@@ -2274,8 +2275,9 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
}).
error
(
done
)
}).
error
(
done
)
})
})
it
(
'should not overwrite a specified deletedAt (complex query)'
,
function
(
done
)
{
it
(
'should not overwrite a specified deletedAt (complex query)
by setting paranoid: false
'
,
function
(
done
)
{
this
.
User
.
findAll
({
this
.
User
.
findAll
({
paranoid
:
false
,
where
:
[
where
:
[
this
.
sequelize
.
or
({
username
:
'leia'
},
{
username
:
'luke'
}),
this
.
sequelize
.
or
({
username
:
'leia'
},
{
username
:
'luke'
}),
this
.
sequelize
.
and
(
this
.
sequelize
.
and
(
...
...
test/dao.test.js
View file @
c5ef474
...
@@ -1305,6 +1305,90 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
...
@@ -1305,6 +1305,90 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
})
})
})
})
it
(
"sql should have paranoid condition"
,
function
(
done
)
{
var
self
=
this
;
self
.
ParanoidUser
.
create
({
username
:
'cuss'
})
.
then
(
function
()
{
return
self
.
ParanoidUser
.
findAll
();
})
.
then
(
function
(
users
)
{
expect
(
users
).
to
.
have
.
length
(
1
);
return
users
[
0
].
destroy
();
})
.
then
(
function
()
{
return
self
.
ParanoidUser
.
findAll
();
})
.
then
(
function
(
users
)
{
expect
(
users
).
to
.
have
.
length
(
0
);
})
.
done
(
done
)
.
catch
(
done
);
});
it
(
"sequelize.and as where should include paranoid condition"
,
function
(
done
)
{
var
self
=
this
;
self
.
ParanoidUser
.
create
({
username
:
'cuss'
})
.
then
(
function
()
{
return
self
.
ParanoidUser
.
findAll
({
where
:
self
.
sequelize
.
and
({
username
:
'cuss'
})
});
})
.
then
(
function
(
users
)
{
expect
(
users
).
to
.
have
.
length
(
1
);
return
users
[
0
].
destroy
();
})
.
then
(
function
()
{
return
self
.
ParanoidUser
.
findAll
({
where
:
self
.
sequelize
.
and
({
username
:
'cuss'
})
});
})
.
then
(
function
(
users
)
{
expect
(
users
).
to
.
have
.
length
(
0
);
})
.
done
(
done
)
.
catch
(
done
);
});
it
(
"sequelize.or as where should include paranoid condition"
,
function
(
done
)
{
var
self
=
this
;
self
.
ParanoidUser
.
create
({
username
:
'cuss'
})
.
then
(
function
()
{
return
self
.
ParanoidUser
.
findAll
({
where
:
self
.
sequelize
.
or
({
username
:
'cuss'
})
});
})
.
then
(
function
(
users
)
{
expect
(
users
).
to
.
have
.
length
(
1
);
return
users
[
0
].
destroy
();
})
.
then
(
function
()
{
return
self
.
ParanoidUser
.
findAll
({
where
:
self
.
sequelize
.
or
({
username
:
'cuss'
})
});
})
.
then
(
function
(
users
)
{
expect
(
users
).
to
.
have
.
length
(
0
);
})
.
done
(
done
)
.
catch
(
done
);
});
it
(
"escapes a single single quotes properly in where clauses"
,
function
(
done
)
{
it
(
"escapes a single single quotes properly in where clauses"
,
function
(
done
)
{
var
self
=
this
var
self
=
this
...
...
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