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 ea5afbfd
authored
Mar 30, 2019
by
Wei-Liang Liou
Committed by
Sushant
Mar 30, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(model): map fields only once when saving (#10658)
1 parent
33e140d9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
1 deletions
lib/model.js
test/integration/model.test.js
lib/model.js
View file @
ea5afbf
...
@@ -3784,7 +3784,6 @@ class Model {
...
@@ -3784,7 +3784,6 @@ class Model {
args
=
[
this
,
this
.
constructor
.
getTableName
(
options
),
values
,
options
];
args
=
[
this
,
this
.
constructor
.
getTableName
(
options
),
values
,
options
];
}
else
{
}
else
{
where
=
this
.
where
(
true
);
where
=
this
.
where
(
true
);
where
=
Utils
.
mapValueFieldNames
(
where
,
Object
.
keys
(
where
),
this
.
constructor
);
if
(
versionAttr
)
{
if
(
versionAttr
)
{
values
[
versionFieldName
]
=
parseInt
(
values
[
versionFieldName
],
10
)
+
1
;
values
[
versionFieldName
]
=
parseInt
(
values
[
versionFieldName
],
10
)
+
1
;
}
}
...
...
test/integration/model.test.js
View file @
ea5afbf
...
@@ -813,6 +813,40 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -813,6 +813,40 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
});
});
describe
(
'save'
,
()
=>
{
it
(
'should mapping the correct fields when saving instance. see #10589'
,
function
()
{
const
User
=
this
.
sequelize
.
define
(
'User'
,
{
id3
:
{
field
:
'id'
,
type
:
Sequelize
.
INTEGER
,
primaryKey
:
true
},
id
:
{
field
:
'id2'
,
type
:
Sequelize
.
INTEGER
,
allowNull
:
false
},
id2
:
{
field
:
'id3'
,
type
:
Sequelize
.
INTEGER
,
allowNull
:
false
}
});
// Setup
return
this
.
sequelize
.
sync
({
force
:
true
}).
then
(()
=>
{
return
User
.
create
({
id3
:
94
,
id
:
87
,
id2
:
943
});
})
// Test
.
then
(()
=>
User
.
findByPk
(
94
))
.
then
(
user
=>
user
.
set
(
'id2'
,
8877
))
.
then
(
user
=>
user
.
save
({
id2
:
8877
}))
// Validate
.
then
(()
=>
User
.
findByPk
(
94
))
.
then
(
user
=>
expect
(
user
.
id2
).
to
.
equal
(
8877
));
});
});
describe
(
'update'
,
()
=>
{
describe
(
'update'
,
()
=>
{
it
(
'throws an error if no where clause is given'
,
function
()
{
it
(
'throws an error if no where clause is given'
,
function
()
{
const
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
DataTypes
.
STRING
});
const
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
DataTypes
.
STRING
});
...
@@ -827,6 +861,39 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -827,6 +861,39 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
});
});
it
(
'should mapping the correct fields when updating instance. see #10589'
,
function
()
{
const
User
=
this
.
sequelize
.
define
(
'User'
,
{
id3
:
{
field
:
'id'
,
type
:
Sequelize
.
INTEGER
,
primaryKey
:
true
},
id
:
{
field
:
'id2'
,
type
:
Sequelize
.
INTEGER
,
allowNull
:
false
},
id2
:
{
field
:
'id3'
,
type
:
Sequelize
.
INTEGER
,
allowNull
:
false
}
});
// Setup
return
this
.
sequelize
.
sync
({
force
:
true
}).
then
(()
=>
{
return
User
.
create
({
id3
:
94
,
id
:
87
,
id2
:
943
});
})
// Test
.
then
(()
=>
User
.
findByPk
(
94
))
.
then
(
user
=>
{
return
user
.
update
({
id2
:
8877
});
})
// Validate
.
then
(()
=>
User
.
findByPk
(
94
))
.
then
(
user
=>
expect
(
user
.
id2
).
to
.
equal
(
8877
));
});
if
(
current
.
dialect
.
supports
.
transactions
)
{
if
(
current
.
dialect
.
supports
.
transactions
)
{
it
(
'supports transactions'
,
function
()
{
it
(
'supports transactions'
,
function
()
{
return
Support
.
prepareTransactionTest
(
this
.
sequelize
).
then
(
sequelize
=>
{
return
Support
.
prepareTransactionTest
(
this
.
sequelize
).
then
(
sequelize
=>
{
...
...
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