-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Passing Values to the next() in remote hooks. #4320
Comments
If I'm not misunderstand ... try this model.exports = function(MyModel) {
let newModelInstance = null;
MyModel.afterRemote('create', function(ctx, unused, next) {
var NewModel = MyModel.models.User
var body = ctx.req.body;
username = body.Username;
email = body.email;
//..
NewModel.create({
//Variables to be persisted goes here
}, function(err, instance) {
newModelInstance = instance;//for next in the beforeRemote reference
})
})
MyModel.beforeRemote('create', function(ctx, unused, next) {
console.log(newModelInstance);//should be last assign instance in memory...
})
} |
@boakye-agyeman next() only takes an error argument, we cannot pass any data values into it. please take a look at https://loopback.io/doc/en/lb3/Remote-hooks.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
MyModel.afterRemote('create', function(ctx, unused,next){
var NewModel = MyModel.models.User
//Now I will pass the context variables to a variable.
// Example
var body = ctx.req.body;
username = body.Username;
email = body.email;
// I want to create an object and persist into a different model instance. I called that model at the // // top as NewModel referencing the User model.
// The creation was done by manipulating the current ctx variables.
NewModel.create({Variables to be persisted goes here}, function(err,instance){
})
})
......
Now what I want is to pass the instance of the NewModel Creation to the next in the beforeRemote hook. How do I go about it? Ill be glad to provide further details
The text was updated successfully, but these errors were encountered: