The issue
I have a Sequelize model called Test with an unique field: value (primary key). I'm using SQLite as database management system.
If I use ignoreDuplicates: true as option of bulkCreate() it's supposed to bulkCreate will ignore the new inserts if they exist on database. That works great, but all the objects of the array returned by the method bulkCreate() always have set the isNewRecord attribute to false, even when a new record was inserted on the database.
Code
const items = [ {value: 'a'}, {value: 'b'} ]; // Items to save on database.
const results = await Test.bulkCreate(items, {
ignoreDuplicates: true // Ignore duplicate records
});
After the first execution of bulkCreate() and the database empty, the value of results:
[
Test {
dataValues: {
value: 'a',
createdAt: 2020-07-12T12:01:08.695Z,
updatedAt: 2020-07-12T12:01:08.695Z
},
_previousDataValues: {
value: 'a',
createdAt: 2020-07-12T12:01:08.695Z,
updatedAt: 2020-07-12T12:01:08.695Z
},
_changed: Set {},
_options: {
isNewRecord: true,
_schema: null,
_schemaDelimiter: '',
include: undefined
},
isNewRecord: false
},
Test {
dataValues: {
value: 'b',
createdAt: 2020-07-12T12:01:08.695Z,
updatedAt: 2020-07-12T12:01:08.695Z
},
_previousDataValues: {
value: 'b',
createdAt: 2020-07-12T12:01:08.695Z,
updatedAt: 2020-07-12T12:01:08.695Z
},
_changed: Set {},
_options: {
isNewRecord: true,
_schema: null,
_schemaDelimiter: '',
include: undefined
},
isNewRecord: false
}
]
I expected true for all isNewRecord in the first execution. What am I missing?
Environment
- Windows 10 Pro
- NodeJS v12.16.2
sequelize: 6.3.3sqlite3: 5.0.0
Sequelize docs
isNewRecord of Model:
ignoreDuplicates of bulkCreate():

