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 ff1c97cd
authored
Dec 09, 2018
by
Sushant
Committed by
GitHub
Dec 09, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(update): skips update when nothing to update (#10248)
1 parent
510ff542
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
1 deletions
lib/model.js
test/integration/model/update.test.js
lib/model.js
View file @
ff1c97c
...
@@ -2975,11 +2975,19 @@ class Model {
...
@@ -2975,11 +2975,19 @@ class Model {
});
});
}
}
}).
then
(
results
=>
{
}).
then
(
results
=>
{
// Update already done row-by-row - exit
if
(
results
)
{
if
(
results
)
{
// Update already done row-by-row - exit
return
[
results
.
length
,
results
];
return
[
results
.
length
,
results
];
}
}
// only updatedAt is being passed, then skip update
if
(
_
.
isEmpty
(
valuesUse
)
||
Object
.
keys
(
valuesUse
).
length
===
1
&&
valuesUse
[
this
.
_timestampAttributes
.
updatedAt
]
)
{
return
[
0
];
}
valuesUse
=
Utils
.
mapValueFieldNames
(
valuesUse
,
options
.
fields
,
this
);
valuesUse
=
Utils
.
mapValueFieldNames
(
valuesUse
,
options
.
fields
,
this
);
options
=
Utils
.
mapOptionFieldNames
(
options
,
this
);
options
=
Utils
.
mapOptionFieldNames
(
options
,
this
);
options
.
hasTrigger
=
this
.
options
?
this
.
options
.
hasTrigger
:
false
;
options
.
hasTrigger
=
this
.
options
?
this
.
options
.
hasTrigger
:
false
;
...
...
test/integration/model/update.test.js
View file @
ff1c97c
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
const
Support
=
require
(
'../support'
);
const
Support
=
require
(
'../support'
);
const
DataTypes
=
require
(
'../../../lib/data-types'
);
const
DataTypes
=
require
(
'../../../lib/data-types'
);
const
chai
=
require
(
'chai'
);
const
chai
=
require
(
'chai'
);
const
sinon
=
require
(
'sinon'
);
const
expect
=
chai
.
expect
;
const
expect
=
chai
.
expect
;
const
current
=
Support
.
sequelize
;
const
current
=
Support
.
sequelize
;
const
_
=
require
(
'lodash'
);
const
_
=
require
(
'lodash'
);
...
@@ -35,6 +36,59 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -35,6 +36,59 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}));
}));
});
});
describe
(
'skips update query'
,
()
=>
{
it
(
'if no data to update'
,
function
()
{
const
spy
=
sinon
.
spy
();
return
this
.
Account
.
create
({
ownerId
:
3
}).
then
(()
=>
{
return
this
.
Account
.
update
({
unknownField
:
'haha'
},
{
where
:
{
ownerId
:
3
},
logging
:
spy
});
}).
then
(
result
=>
{
expect
(
result
[
0
]).
to
.
equal
(
0
);
expect
(
spy
.
called
,
'Update query was issued when no data to update'
).
to
.
be
.
false
;
});
});
it
(
'skips when timestamps disabled'
,
function
()
{
const
Model
=
this
.
sequelize
.
define
(
'Model'
,
{
ownerId
:
{
type
:
DataTypes
.
INTEGER
,
allowNull
:
false
,
field
:
'owner_id'
},
name
:
{
type
:
DataTypes
.
STRING
}
},
{
timestamps
:
false
});
const
spy
=
sinon
.
spy
();
return
Model
.
sync
({
force
:
true
})
.
then
(()
=>
Model
.
create
({
ownerId
:
3
}))
.
then
(()
=>
{
return
Model
.
update
({
unknownField
:
'haha'
},
{
where
:
{
ownerId
:
3
},
logging
:
spy
});
})
.
then
(
result
=>
{
expect
(
result
[
0
]).
to
.
equal
(
0
);
expect
(
spy
.
called
,
'Update query was issued when no data to update'
).
to
.
be
.
false
;
});
});
});
it
(
'changed should be false after reload'
,
function
()
{
it
(
'changed should be false after reload'
,
function
()
{
return
this
.
Account
.
create
({
ownerId
:
2
,
name
:
'foo'
})
return
this
.
Account
.
create
({
ownerId
:
2
,
name
:
'foo'
})
.
then
(
account
=>
{
.
then
(
account
=>
{
...
...
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