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 ac23e551
authored
Jan 08, 2014
by
Sascha Gehlich
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into feature/create-relation-objects
2 parents
73d07be6
3b2c0ee0
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
113 additions
and
2 deletions
lib/dao-factory.js
test/dao-factory.test.js
lib/dao-factory.js
View file @
ac23e55
...
@@ -1191,17 +1191,27 @@ module.exports = (function() {
...
@@ -1191,17 +1191,27 @@ module.exports = (function() {
options
.
where
=
options
.
where
||
{}
options
.
where
=
options
.
where
||
{}
var
deletedAtCol
=
Utils
.
_
.
underscoredIf
(
this
.
options
.
deletedAt
,
this
.
options
.
underscored
)
var
deletedAtCol
=
Utils
.
_
.
underscoredIf
(
this
.
options
.
deletedAt
,
this
.
options
.
underscored
)
,
quoteIdentifiedDeletedAtCol
=
this
.
QueryInterface
.
quoteIdentifier
(
deletedAtCol
)
// Don't overwrite our explicit deletedAt search value if we provide one
// Don't overwrite our explicit deletedAt search value if we provide one
if
(
!!
options
.
where
[
deletedAtCol
])
{
if
(
!!
options
.
where
[
deletedAtCol
])
{
return
options
return
options
}
}
if
(
this
.
tableName
)
{
quoteIdentifiedDeletedAtCol
=
this
.
QueryInterface
.
quoteIdentifier
(
this
.
tableName
)
+
'.'
+
quoteIdentifiedDeletedAtCol
}
if
(
typeof
options
.
where
===
"string"
)
{
if
(
typeof
options
.
where
===
"string"
)
{
options
.
where
+=
' AND '
+
this
.
QueryInterface
.
quoteIdentifier
(
deletedAtCol
)
+
' IS NULL '
options
.
where
+=
' AND '
+
quoteIdentifiedDeletedAtCol
+
' IS NULL '
}
}
else
if
(
Array
.
isArray
(
options
.
where
))
{
else
if
(
Array
.
isArray
(
options
.
where
))
{
options
.
where
[
0
]
+=
' AND '
+
this
.
QueryInterface
.
quoteIdentifier
(
deletedAtCol
)
+
' IS NULL '
// Don't overwrite our explicit deletedAt search value if we provide one
if
(
options
.
where
[
0
].
indexOf
(
deletedAtCol
)
!==
-
1
)
{
return
options
}
options
.
where
[
0
]
+=
' AND '
+
quoteIdentifiedDeletedAtCol
+
' IS NULL '
}
else
{
}
else
{
options
.
where
[
deletedAtCol
]
=
null
options
.
where
[
deletedAtCol
]
=
null
}
}
...
...
test/dao-factory.test.js
View file @
ac23e55
...
@@ -1679,4 +1679,105 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
...
@@ -1679,4 +1679,105 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
})
})
})
})
describe
(
'paranoid is true and where is an array'
,
function
()
{
beforeEach
(
function
(
done
)
{
this
.
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
DataTypes
.
STRING
},
{
paranoid
:
true
})
this
.
Project
=
this
.
sequelize
.
define
(
'Project'
,
{
title
:
DataTypes
.
STRING
},
{
paranoid
:
true
})
this
.
Project
.
hasMany
(
this
.
User
)
this
.
User
.
hasMany
(
this
.
Project
)
var
self
=
this
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
self
.
User
.
bulkCreate
([{
username
:
'leia'
},
{
username
:
'luke'
},
{
username
:
'vader'
}]).
success
(
function
()
{
self
.
Project
.
bulkCreate
([{
title
:
'republic'
},{
title
:
'empire'
}]).
success
(
function
()
{
self
.
User
.
findAll
().
success
(
function
(
users
){
self
.
Project
.
findAll
().
success
(
function
(
projects
){
var
leia
=
users
[
0
]
,
luke
=
users
[
1
]
,
vader
=
users
[
2
]
,
republic
=
projects
[
0
]
,
empire
=
projects
[
1
]
leia
.
setProjects
([
republic
]).
success
(
function
(){
luke
.
setProjects
([
republic
]).
success
(
function
(){
vader
.
setProjects
([
empire
]).
success
(
function
(){
leia
.
destroy
().
success
(
function
()
{
done
()
})
})
})
})
})
})
})
})
})
})
it
(
'should not fail with an include'
,
function
(
done
)
{
var
tableName
=
''
,
ident
=
this
.
sequelize
.
queryInterface
.
QueryGenerator
.
quoteIdentifier
,
escape
=
this
.
sequelize
.
queryInterface
.
QueryGenerator
.
escape
if
(
this
.
Project
.
tableName
)
{
tableName
=
ident
(
this
.
Project
.
tableName
)
+
'.'
}
this
.
User
.
findAll
({
where
:
[
tableName
+
ident
(
'title'
)
+
' = '
+
escape
(
'republic'
)
],
include
:
[
{
model
:
this
.
Project
}
]
}).
success
(
function
(
users
){
try
{
expect
(
users
.
length
).
to
.
be
.
equal
(
1
)
expect
(
users
[
0
].
username
).
to
.
be
.
equal
(
'luke'
)
done
()
}
catch
(
e
){
done
(
e
)
}
}).
error
(
done
)
})
it
(
'should not overwrite a specified deletedAt'
,
function
(
done
)
{
var
tableName
=
''
,
ident
=
this
.
sequelize
.
queryInterface
.
QueryGenerator
.
quoteIdentifier
if
(
this
.
User
.
tableName
)
{
tableName
=
ident
(
this
.
User
.
tableName
)
+
'.'
}
this
.
User
.
findAll
({
where
:
[
tableName
+
ident
(
'deletedAt'
)
+
' IS NOT NULL '
],
include
:
[
{
model
:
this
.
Project
}
]
}).
success
(
function
(
users
){
try
{
expect
(
users
.
length
).
to
.
be
.
equal
(
1
)
expect
(
users
[
0
].
username
).
to
.
be
.
equal
(
'leia'
)
done
()
}
catch
(
e
){
done
(
e
)
}
}).
error
(
done
)
})
})
})
})
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