node-orm2 icon indicating copy to clipboard operation
node-orm2 copied to clipboard

Get Last Insert ID on create method

Open shoaibmerchant opened this issue 11 years ago • 2 comments

I am using MySQL as the database with the orm and my Primary Key is set as Auto-Increment. Is there any way to retrieve the last Insert ID on create for the PK or any existing implementation that would help.

shoaibmerchant avatar Jul 15 '14 08:07 shoaibmerchant

+1

The idea of a single create, instead of the create that expects an array is very handy. Specifically because you can then just return the created object (ID and all).

Person.create({ name: "John", surname: "Doe" }, function (err, John) {
    // John.id is set.
});

n1c avatar Oct 09 '14 14:10 n1c

+1

darkpixel avatar Aug 30 '16 01:08 darkpixel