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 f62ad887
authored
Apr 09, 2014
by
Tiago Ribeiro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add filtering support to increment/decrement
1 parent
c6bd7b2e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
2 deletions
lib/dao.js
test/dao.test.js
lib/dao.js
View file @
f62ad88
...
...
@@ -546,6 +546,7 @@ module.exports = (function() {
var
identifier
=
this
.
__options
.
hasPrimaryKeys
?
this
.
primaryKeyValues
:
{
id
:
this
.
id
}
,
updatedAtAttr
=
this
.
Model
.
_timestampAttributes
.
updatedAt
,
values
=
{}
,
where
if
(
countOrOptions
===
undefined
)
{
countOrOptions
=
{
by
:
1
,
transaction
:
null
}
...
...
@@ -555,9 +556,12 @@ module.exports = (function() {
countOrOptions
=
Utils
.
_
.
extend
({
by
:
1
,
attributes
:
{}
attributes
:
{},
where
:
{}
},
countOrOptions
)
where
=
_
.
extend
(
countOrOptions
.
where
,
identifier
);
if
(
Utils
.
_
.
isString
(
fields
))
{
values
[
fields
]
=
countOrOptions
.
by
}
else
if
(
Utils
.
_
.
isArray
(
fields
))
{
...
...
@@ -572,7 +576,7 @@ module.exports = (function() {
countOrOptions
.
attributes
[
updatedAtAttr
]
=
Utils
.
now
(
this
.
Model
.
daoFactoryManager
.
sequelize
.
options
.
dialect
)
}
return
this
.
QueryInterface
.
increment
(
this
,
this
.
QueryInterface
.
QueryGenerator
.
addSchema
(
this
.
Model
.
tableName
,
this
.
Model
.
options
.
schema
),
values
,
identifier
,
countOrOptions
)
return
this
.
QueryInterface
.
increment
(
this
,
this
.
QueryInterface
.
QueryGenerator
.
addSchema
(
this
.
Model
.
tableName
,
this
.
Model
.
options
.
schema
),
values
,
where
,
countOrOptions
)
}
DAO
.
prototype
.
decrement
=
function
(
fields
,
countOrOptions
)
{
...
...
test/dao.test.js
View file @
f62ad88
...
...
@@ -294,6 +294,18 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
})
})
it
(
'supports where conditions'
,
function
(
done
)
{
var
self
=
this
this
.
User
.
find
(
1
).
complete
(
function
(
err
,
user1
)
{
user1
.
increment
([
'aNumber'
],
{
by
:
2
,
where
:
{
bNumber
:
1
}
}).
complete
(
function
()
{
self
.
User
.
find
(
1
).
complete
(
function
(
err
,
user3
)
{
expect
(
user3
.
aNumber
).
to
.
be
.
equal
(
0
)
done
()
})
})
})
})
it
(
'with array'
,
function
(
done
)
{
var
self
=
this
this
.
User
.
find
(
1
).
complete
(
function
(
err
,
user1
)
{
...
...
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