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 7fc6f21b
authored
May 16, 2015
by
Ruben Bridgewater
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix bulk create not inserting NULL for undefined values. Fixes #3670
1 parent
7c9d1d7b
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
29 additions
and
25 deletions
changelog.md
lib/dialects/abstract/query-generator.js
lib/model.js
lib/utils.js
test/integration/model/create.test.js
changelog.md
View file @
7fc6f21
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
-
[
BUG
]
fix showIndexQuery so appropriate indexes are returned when a schema is used
-
[
BUG
]
fix showIndexQuery so appropriate indexes are returned when a schema is used
-
[
BUG
]
Fix addIndexQuery error when the model has a schema
-
[
BUG
]
Fix addIndexQuery error when the model has a schema
-
[
BUG
]
Fix app crash in sqlite while running in special unique constraint errors
[
3730
](
https://github.com/sequelize/sequelize/pull/3730
)
-
[
BUG
]
Fix app crash in sqlite while running in special unique constraint errors
[
3730
](
https://github.com/sequelize/sequelize/pull/3730
)
-
[
BUG
]
Fix bulkCreate: do not insert NULL for undefined values
[
3729
](
https://github.com/sequelize/sequelize/pull/3729
)
# 2.1.3
# 2.1.3
-
[
BUG
]
Fix regression introduced in 2.1.2: updatedAt not set anymore
[
3667
](
https://github.com/sequelize/sequelize/pull/3667
)
-
[
BUG
]
Fix regression introduced in 2.1.2: updatedAt not set anymore
[
3667
](
https://github.com/sequelize/sequelize/pull/3667
)
...
...
lib/dialects/abstract/query-generator.js
View file @
7fc6f21
...
@@ -275,7 +275,7 @@ module.exports = (function() {
...
@@ -275,7 +275,7 @@ module.exports = (function() {
Parameters: table name + list of hashes of attribute-value-pairs.
Parameters: table name + list of hashes of attribute-value-pairs.
*/
*/
/* istanbul ignore next */
/* istanbul ignore next */
bulkInsertQuery
:
function
(
tableName
,
attrValueHashes
)
{
bulkInsertQuery
:
function
(
tableName
,
attrValueHashes
,
options
,
modelAttributes
)
{
throwMethodUndefined
(
'bulkInsertQuery'
);
throwMethodUndefined
(
'bulkInsertQuery'
);
},
},
...
...
lib/model.js
View file @
7fc6f21
...
@@ -1334,11 +1334,7 @@ module.exports = (function() {
...
@@ -1334,11 +1334,7 @@ module.exports = (function() {
}
}
}).
then
(
function
()
{
}).
then
(
function
()
{
instances
.
forEach
(
function
(
instance
)
{
instances
.
forEach
(
function
(
instance
)
{
// Filter dataValues by options.fields
var
values
=
Utils
.
mapValueFieldNames
(
instance
.
dataValues
,
options
.
fields
,
self
);
var
values
=
{};
options
.
fields
.
forEach
(
function
(
field
)
{
values
[
field
]
=
instance
.
dataValues
[
field
];
});
// set createdAt/updatedAt attributes
// set createdAt/updatedAt attributes
if
(
createdAtAttr
&&
!
values
[
createdAtAttr
])
{
if
(
createdAtAttr
&&
!
values
[
createdAtAttr
])
{
...
@@ -1398,21 +1394,6 @@ module.exports = (function() {
...
@@ -1398,21 +1394,6 @@ module.exports = (function() {
return
Utils
.
_
.
omit
(
instance
.
dataValues
,
self
.
_virtualAttributes
);
return
Utils
.
_
.
omit
(
instance
.
dataValues
,
self
.
_virtualAttributes
);
});
});
var
rawAttribute
;
// Map field names
records
.
forEach
(
function
(
values
)
{
for
(
var
attr
in
values
)
{
if
(
values
.
hasOwnProperty
(
attr
))
{
rawAttribute
=
self
.
rawAttributes
[
attr
];
if
(
rawAttribute
.
field
&&
rawAttribute
.
field
!==
rawAttribute
.
fieldName
)
{
values
[
self
.
rawAttributes
[
attr
].
field
]
=
values
[
attr
];
delete
values
[
attr
];
}
}
}
});
// Map attributes for serial identification
// Map attributes for serial identification
var
attributes
=
{};
var
attributes
=
{};
for
(
var
attr
in
self
.
tableAttributes
)
{
for
(
var
attr
in
self
.
tableAttributes
)
{
...
...
lib/utils.js
View file @
7fc6f21
...
@@ -163,12 +163,11 @@ var Utils = module.exports = {
...
@@ -163,12 +163,11 @@ var Utils = module.exports = {
fields
.
forEach
(
function
(
attr
)
{
fields
.
forEach
(
function
(
attr
)
{
if
(
dataValues
[
attr
]
!==
undefined
&&
!
Model
.
_isVirtualAttribute
(
attr
))
{
if
(
dataValues
[
attr
]
!==
undefined
&&
!
Model
.
_isVirtualAttribute
(
attr
))
{
values
[
attr
]
=
dataValues
[
attr
];
// Field name mapping
// Field name mapping
if
(
Model
.
rawAttributes
[
attr
]
&&
Model
.
rawAttributes
[
attr
].
field
&&
Model
.
rawAttributes
[
attr
].
field
!==
attr
)
{
if
(
Model
.
rawAttributes
[
attr
]
&&
Model
.
rawAttributes
[
attr
].
field
&&
Model
.
rawAttributes
[
attr
].
field
!==
attr
)
{
values
[
Model
.
rawAttributes
[
attr
].
field
]
=
values
[
attr
];
values
[
Model
.
rawAttributes
[
attr
].
field
]
=
dataValues
[
attr
];
delete
values
[
attr
];
}
else
{
values
[
attr
]
=
dataValues
[
attr
];
}
}
}
}
});
});
...
...
test/integration/model/create.test.js
View file @
7fc6f21
...
@@ -1351,6 +1351,29 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -1351,6 +1351,29 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
});
});
});
it
(
'should not insert NULL for unused fields'
,
function
()
{
var
Beer
=
this
.
sequelize
.
define
(
'Beer'
,
{
style
:
Sequelize
.
STRING
,
size
:
Sequelize
.
INTEGER
,
});
return
Beer
.
sync
({
force
:
true
}).
then
(
function
()
{
return
Beer
.
bulkCreate
([{
style
:
'ipa'
}],
{
logging
:
function
(
sql
)
{
if
(
dialect
===
'postgres'
)
{
expect
(
sql
.
indexOf
(
'INSERT INTO "Beers" ("id","style","createdAt","updatedAt") VALUES (DEFAULT'
)).
not
.
be
.
equal
(
-
1
);
}
else
if
(
dialect
===
'mssql'
)
{
expect
(
sql
.
indexOf
(
'INSERT INTO [Beers] ([style],[createdAt],[updatedAt]) VALUES'
)).
not
.
be
.
equal
(
-
1
);
}
else
{
// mysql, sqlite, mariadb
expect
(
sql
.
indexOf
(
'INSERT INTO `Beers` (`id`,`style`,`createdAt`,`updatedAt`) VALUES (NULL'
)).
not
.
be
.
equal
(
-
1
);
}
}
});
});
});
it
(
'properly handles disparate field lists'
,
function
()
{
it
(
'properly handles disparate field lists'
,
function
()
{
var
self
=
this
var
self
=
this
,
data
=
[{
username
:
'Peter'
,
secretValue
:
'42'
,
uniqueName
:
'1'
},
,
data
=
[{
username
:
'Peter'
,
secretValue
:
'42'
,
uniqueName
:
'1'
},
...
...
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