loopback icon indicating copy to clipboard operation
loopback copied to clipboard

Delete some property of the request body doesn't work

Open agregoris opened this issue 11 years ago • 8 comments

I tried the next sentences and no work ("grant" is the property I'm trying delete)

User.beforeRemote('prototype.__create__guides', function(ctx, user, next) {
  ...
  // I tried these
  delete ctx.req.body.grant; // not working
  delete ctx.args.data.grant; // not working
  ...

agregoris avatar Aug 20 '15 10:08 agregoris

http.IncomingMessage fields are not processed in the data model phase (to do that it should be done at middleware level).

It works with the following (note that using I'm lodash to clone and omit certain properties):

User.beforeRemote('prototype.__create__guides', function (ctx, user, next) {
  ctx.args.data = _.omit(ctx.args.data, 'grant')
  next()
})

h2non avatar Aug 20 '15 15:08 h2non

@onnoll Hav eyou tried @h2non's solution? Is this issue good to close?

superkhau avatar Dec 01 '15 07:12 superkhau

I have the same issue, @h2non solution didn't work for me.

Edit: This did the trick: ctx.args.data.myProperty = undefined;

Nivl avatar Jan 18 '16 07:01 Nivl

When create related model, ctx.args.data is a model instance. For delete property use modelInstance.unsetAttribute(propertyName) Example: var guides = ctx.args.data guides.unsetAttribute('grant').

mrbatista avatar Jan 18 '16 09:01 mrbatista

@Nivl @h2non @onnoll added example in previous comment. See this for more informations.

mrbatista avatar Jan 18 '16 15:01 mrbatista

Are you guys still running into this issue? Can I close this?

superkhau avatar Feb 03 '16 02:02 superkhau

@mrbatista solution was good for me.

Nivl avatar Feb 03 '16 02:02 Nivl

Cool. Gonna close this. Please open a new issue if you are still running into problems.

superkhau avatar Feb 03 '16 02:02 superkhau