I want to save several objects into a database that I have defined in my NodeJS (express) app. The database module is node-orm2 and the database is an SQLite.
var record;
record = {
'title' : 'Title 1'
};
req.models.myModel.create(record, function (err, item) {
console.log('row id: ' + item.id);
});
record = {
'title' : 'Title 2'
};
req.models.myModel.create(record, function (err, item) {
console.log('row id: ' + item.id);
});
record = {
'title' : 'Title 3'
};
req.models.myModel.create(record, function (err, item) {
console.log('row id: ' + item.id);
});
The output is:
row id: 3
row id: 3
row id: 3
But I expect it to be like this (or in a different order):
row id: 1
row id: 2
row id: 3
What am I doing wrong? I tried to create the models in other ways, and I also tried the save method. I get the same results.
When I look at the database, I see that the three rows were added with the expected ids (1,2,3). So why is node-orm2 not returning the right id? I need to work with this ids to add more objects to the database.