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
bulkCreate with updateOnDuplicate do not work with individualHooks #10461
Comments
I am having a similar problem with getting the updateOnDuplicate option to work. What are you doing?
What do you expect to happen?
What is actually happening?
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Can someone please test with the latest 5.x version? |
This fails because const Sequelize = require('./index');
const sequelize = require('./test/support').createSequelizeInstance();
const Op = Sequelize.Op;
const Model = sequelize.define('Model', {
name: Sequelize.STRING,
company: {
type: Sequelize.STRING,
unique: true
}
});
(async () => {
await Model.sync({ force: true });
await Model.bulkCreate([
{
name: 'abc',
company: 'c1'
},
{
name: 'xyz',
company: 'c2'
}
]);
const result = await Model.bulkCreate([
{
name: 'cds',
company: 'c1'
},
{
name: 'xsyz',
company: 'c2'
}
], {
updateOnDuplicate: ['name'],
individualHooks: true
});
console.log(result);
})(); |
This comment has been minimized.
This comment has been minimized.
same issue with sequelize 5.15.1 |
guys i am using bulkCreate at too many places. it works fine but thing is if query finds and unique key failure then it updates otherwise it creates. you should keep in mind about unique key to pass in you query like const result = await Model.bulkCreate([ |
so here id is primary key or unique if it exists then it will update otherwise it will create |
Do we have any update on this or some work around? |
This could have been the most awesome feature. But this bug is ruining it. A little attention to this issue will be appreciated. Regards. |
What are you doing?
What do you expect to happen?
What is actually happening?
Dialect: mysql
Dialect version: XXX
__Database version: 5.7
__Sequelize version: 4.42.0
__Tested with latest release:4.42.0
Bug is https://github.com/sequelize/sequelize/blob/v4/lib/model.js#L2406 modelInstance.save do not handle updateOnDuplicate.
It can be fixed if https://github.com/sequelize/sequelize/blob/v4/lib/query-interface.js#L896
will check updateOnDuplicate for mySQL and use upsertQuery in this case
The text was updated successfully, but these errors were encountered: