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

Save and create callbacks have different behaviors #5

Closed
juggy opened this issue Nov 17, 2011 · 3 comments
Closed

Save and create callbacks have different behaviors #5

juggy opened this issue Nov 17, 2011 · 3 comments

Comments

@juggy
Copy link
Contributor

juggy commented Nov 17, 2011

It seems that create callback is:

User.create({...}, function(err, user){});

and save callback is

User.save(function(err){});

and is not bound to the object.

I would stick with one or the other. My preference is to use an explicit argument like create to pass the object to the callback.

Should be a pretty small change.

@1602
Copy link
Owner

1602 commented Nov 17, 2011

User.create is a class method, and of course it should have created user as argument. user.save is instance method, you only can call save on instance, not on class (User), this is a reason why save callback haven't any arguments except err, you already should have instance and there's no reason to pass it as argument additionally. Or, maybe I misunderstood smth?

@juggy
Copy link
Contributor Author

juggy commented Nov 17, 2011

You are right. Create is class method so you do not have access to the object already. Save is an instance method so you already have access. But in this later case, you assume the code will be as follow:

object.save( function(err){ /* access object here */});

What happens if you do not have access to the local var object? As with passed in callback like:

object.save( callback_define_somewhere_else );

@1602
Copy link
Owner

1602 commented Nov 17, 2011

Yeah, I got an idea! Thank you for clarifying, will tune as soon as get my laptop working.

On 17.11.2011, at 23:20, Julien Guimontreply@reply.github.com wrote:

You are right. Create is class method so you do not have access to the object already. Save is an instance method so you already have access. But in this later case, you assume the code will be as follow:

object.save( function(err){ /* access object here */});

What happens if you do not have access to the local var object? As with passed in callback like:

object.save( callback_define_somewhere_else );


Reply to this email directly or view it on GitHub:
#5 (comment)

@1602 1602 closed this as completed Jan 10, 2012
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