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 71ed0c1a
authored
Apr 12, 2015
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(model): dont remove primary key if using default value in upsert, closes #3247
1 parent
e9434d0a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
3 deletions
lib/instance.js
lib/model.js
test/integration/model/upsert.test.js
lib/instance.js
View file @
71ed0c1
...
...
@@ -530,7 +530,7 @@ module.exports = (function() {
options
.
fields
.
push
(
createdAtAttr
);
}
if
(
primaryKeyAttribute
&&
!
primaryKeyAttribute
.
autoIncrement
&&
options
.
fields
.
indexOf
(
primaryKeyName
)
<
0
)
{
if
(
primaryKeyAttribute
&&
primaryKeyAttribute
.
defaultValue
&&
options
.
fields
.
indexOf
(
primaryKeyName
)
<
0
)
{
options
.
fields
.
unshift
(
primaryKeyName
);
}
}
...
...
lib/model.js
View file @
71ed0c1
...
...
@@ -1224,7 +1224,7 @@ module.exports = (function() {
var
createdAtAttr
=
this
.
_timestampAttributes
.
createdAt
,
updatedAtAttr
=
this
.
_timestampAttributes
.
updatedAt
,
hadPrimary
=
this
.
primaryKeyField
in
values
,
hadPrimary
=
this
.
primaryKeyField
in
values
||
this
.
primaryKeyAttribute
in
values
,
instance
=
this
.
build
(
values
);
return
instance
.
hookValidate
(
options
).
bind
(
this
).
then
(
function
()
{
...
...
@@ -1240,7 +1240,7 @@ module.exports = (function() {
// Build adds a null value for the primary key, if none was given by the user.
// We need to remove that because of some Postgres technicalities.
if
(
!
hadPrimary
)
{
if
(
!
hadPrimary
&&
!
this
.
rawAttributes
[
this
.
primaryKeyAttribute
].
defaultValue
)
{
delete
values
[
this
.
primaryKeyField
];
}
...
...
test/integration/model/upsert.test.js
View file @
71ed0c1
...
...
@@ -92,6 +92,26 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
});
it
(
'should work with UUIDs wth default values'
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
id
:
{
primaryKey
:
true
,
allowNull
:
false
,
unique
:
true
,
type
:
Sequelize
.
UUID
,
defaultValue
:
Sequelize
.
UUIDV4
},
name
:
{
type
:
Sequelize
.
STRING
,
}
});
return
User
.
sync
({
force
:
true
}).
then
(
function
()
{
return
User
.
upsert
({
name
:
'John Doe'
});
});
});
it
(
'works with upsert on a composite primary key'
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'user'
,
{
a
:
{
...
...
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