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 08e8c92d
authored
May 17, 2015
by
Mick Hansen
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'BridgeAR-fix-bulkCreate'
2 parents
d21fffdc
a13fa96f
Hide 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 @
08e8c92
...
...
@@ -2,6 +2,7 @@
-
[
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 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
)
-
[
BUG
]
Fix API doc generation
#### Backwards compatibility changes
...
...
lib/dialects/abstract/query-generator.js
View file @
08e8c92
...
...
@@ -275,7 +275,7 @@ module.exports = (function() {
Parameters: table name + list of hashes of attribute-value-pairs.
*/
/* istanbul ignore next */
bulkInsertQuery
:
function
(
tableName
,
attrValueHashes
)
{
bulkInsertQuery
:
function
(
tableName
,
attrValueHashes
,
options
,
modelAttributes
)
{
throwMethodUndefined
(
'bulkInsertQuery'
);
},
...
...
lib/model.js
View file @
08e8c92
...
...
@@ -1334,11 +1334,7 @@ module.exports = (function() {
}
}).
then
(
function
()
{
instances
.
forEach
(
function
(
instance
)
{
// Filter dataValues by options.fields
var
values
=
{};
options
.
fields
.
forEach
(
function
(
field
)
{
values
[
field
]
=
instance
.
dataValues
[
field
];
});
var
values
=
Utils
.
mapValueFieldNames
(
instance
.
dataValues
,
options
.
fields
,
self
);
// set createdAt/updatedAt attributes
if
(
createdAtAttr
&&
!
values
[
createdAtAttr
])
{
...
...
@@ -1398,21 +1394,6 @@ module.exports = (function() {
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
var
attributes
=
{};
for
(
var
attr
in
self
.
tableAttributes
)
{
...
...
lib/utils.js
View file @
08e8c92
...
...
@@ -163,12 +163,11 @@ var Utils = module.exports = {
fields
.
forEach
(
function
(
attr
)
{
if
(
dataValues
[
attr
]
!==
undefined
&&
!
Model
.
_isVirtualAttribute
(
attr
))
{
values
[
attr
]
=
dataValues
[
attr
];
// Field name mapping
if
(
Model
.
rawAttributes
[
attr
]
&&
Model
.
rawAttributes
[
attr
].
field
&&
Model
.
rawAttributes
[
attr
].
field
!==
attr
)
{
values
[
Model
.
rawAttributes
[
attr
].
field
]
=
values
[
attr
];
delete
values
[
attr
];
values
[
Model
.
rawAttributes
[
attr
].
field
]
=
dataValues
[
attr
];
}
else
{
values
[
attr
]
=
dataValues
[
attr
];
}
}
});
...
...
test/integration/model/create.test.js
View file @
08e8c92
...
...
@@ -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
()
{
var
self
=
this
,
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