Skip to content
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

about save method and model's id #264

Open
class4cxy opened this issue Dec 11, 2015 · 3 comments
Open

about save method and model's id #264

class4cxy opened this issue Dec 11, 2015 · 3 comments

Comments

@class4cxy
Copy link

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
Copy link
Contributor

mde commented Dec 11, 2015

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

@class4cxy
Copy link
Author

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants