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 3464ade4
authored
May 24, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(model/attributes): support aliased serial attributes for bulkCreate in postgres
1 parent
01113d4f
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
6 deletions
lib/model.js
lib/query-interface.js
test/model/attributes.test.js
lib/model.js
View file @
3464ade
...
@@ -1230,8 +1230,17 @@ module.exports = (function() {
...
@@ -1230,8 +1230,17 @@ module.exports = (function() {
}
}
});
});
// Map attributes for serial identification
var
attributes
=
{};
for
(
var
attr
in
self
.
rawAttributes
)
{
attributes
[
attr
]
=
self
.
rawAttributes
[
attr
];
if
(
self
.
rawAttributes
[
attr
].
field
)
{
attributes
[
self
.
rawAttributes
[
attr
].
field
]
=
self
.
rawAttributes
[
attr
];
}
}
// Insert all records at once
// Insert all records at once
return
self
.
QueryInterface
.
bulkInsert
(
self
.
getTableName
(),
records
,
options
,
self
).
then
(
runAfterCreate
);
return
self
.
QueryInterface
.
bulkInsert
(
self
.
getTableName
(),
records
,
options
,
attributes
).
then
(
runAfterCreate
);
}
else
{
}
else
{
// Records were already saved while running create / update hooks
// Records were already saved while running create / update hooks
return
runAfterCreate
();
return
runAfterCreate
();
...
...
lib/query-interface.js
View file @
3464ade
...
@@ -423,8 +423,8 @@ module.exports = (function() {
...
@@ -423,8 +423,8 @@ module.exports = (function() {
});
});
};
};
QueryInterface
.
prototype
.
bulkInsert
=
function
(
tableName
,
records
,
options
,
Model
)
{
QueryInterface
.
prototype
.
bulkInsert
=
function
(
tableName
,
records
,
options
,
attributes
)
{
var
sql
=
this
.
QueryGenerator
.
bulkInsertQuery
(
tableName
,
records
,
options
,
Model
.
rawA
ttributes
);
var
sql
=
this
.
QueryGenerator
.
bulkInsertQuery
(
tableName
,
records
,
options
,
a
ttributes
);
return
this
.
sequelize
.
query
(
sql
,
null
,
options
);
return
this
.
sequelize
.
query
(
sql
,
null
,
options
);
};
};
...
...
test/model/attributes.test.js
View file @
3464ade
...
@@ -7,10 +7,10 @@ var chai = require('chai')
...
@@ -7,10 +7,10 @@ var chai = require('chai')
,
Support
=
require
(
__dirname
+
'/../support'
)
,
Support
=
require
(
__dirname
+
'/../support'
)
,
DataTypes
=
require
(
__dirname
+
"/../../lib/data-types"
)
,
DataTypes
=
require
(
__dirname
+
"/../../lib/data-types"
)
,
dialect
=
Support
.
getTestDialect
()
,
dialect
=
Support
.
getTestDialect
()
,
datetime
=
require
(
'chai-datetime'
)
,
datetime
=
require
(
'chai-datetime'
)
;
chai
.
use
(
datetime
)
chai
.
use
(
datetime
)
;
chai
.
config
.
includeStack
=
true
chai
.
config
.
includeStack
=
true
;
describe
(
Support
.
getTestDialectTeaser
(
"Model"
),
function
()
{
describe
(
Support
.
getTestDialectTeaser
(
"Model"
),
function
()
{
describe
(
'attributes'
,
function
()
{
describe
(
'attributes'
,
function
()
{
...
...
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