geddy / model

Datastore-agnostic ORM in JavaScript
265 stars 55 forks source link

about `save` method and model's id #264

Open class4cxy opened 8 years ago

class4cxy commented 8 years ago

hi :

my question is after i call the model.save() method, how can i get the current model's id ? and mysql db is design to auto_increment. i was try to use "SELECT LAST_INSERT_ID() as id FROM " after save's callback, but it dosen't suit when concurrent request

mde commented 8 years ago

Once the save callback has executed, the instance you created should have its id property correctly assigned.

class4cxy commented 8 years ago

thanks for reply. you means i can get the id from model instance ? like this ? var user = User.create(params); user.save(function () { alert(user.id) })

class4cxy commented 8 years ago

i found the insertId was return throught this.exec(sql, function (err, res) { ,but it dosen't return back to callback, why ? how could i get the insertId