New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support include option in bulkInsert #11307
feat: support include option in bulkInsert #11307
Conversation
8c518a8
to
203149a
Compare
Codecov Report
@@ Coverage Diff @@
## master #11307 +/- ##
==========================================
- Coverage 96.32% 96.31% -0.02%
==========================================
Files 94 94
Lines 9069 9142 +73
==========================================
+ Hits 8736 8805 +69
- Misses 333 337 +4
Continue to review full report at Codecov.
|
Hey, thanks for the PR. Can you show a code snippet showing the usage as an example? |
The same as regular
|
Looks good, can you update typings https://github.com/sequelize/sequelize/blob/master/types/lib/model.d.ts#L707 |
if (!instance || key === model.primaryKeyAttribute && | ||
instance.get(model.primaryKeyAttribute) && | ||
['mysql', 'mariadb', 'sqlite'].includes(dialect)) { | ||
// The query.js for these DBs is blind, it autoincrements the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For MySQL I have seen this behaviour with updateOnDuplicate #11223 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we can reliably support this unless MySQL adds support for RETURNING * equivalent
That is exactly the root of the problem. PostgreSQL and SQL Server both support RETURNING
and therefore don't have any issue.
@sushantdhiman typings added |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't given new code a deep look but new tests looks good and old one passed :)
Same from me! 👍 |
🎉 This PR is included in version 5.14.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Thanks a lot for implementing this feature, it will be very helpful. I have one observation regarding it though - the options passed to recursiveBulkCreate are as follows:
but this means that if I want to validate at every stage of creation, I cannot just set Would you be willing to either allow the includeOptions to default validate to options.validate, or maybe if that is undesirable, support a validateAll option, which is used to set options.validate to true at the start of recursiveBulkCreate? |
I see your point about @simonbrent, are you using |
@javiertury yes I am. I assume validation is disabled by default because it can be expensive. |
Hi, I'm getting My code is as following:
What could be the issue? Thanks! |
Have any solution for this problem ? @srslyimthebest |
Pull Request check-list
Please make sure to review and check all of these items:
npm run test
ornpm run test-DIALECT
pass with this change (including linting)?Description of change
Closes #3277.
This PR makes
bulkInsert
capable of handling associations. It uses theinclude
option, just like other model methods.It requires only 1 insert statement for each association model. E.g. 100 instances with 100 children and 100 grandchildren are created in 3 insert statements.