loopback icon indicating copy to clipboard operation
loopback copied to clipboard

Inconsistent between GET and DELETE on related models

Open bluestaralone opened this issue 12 years ago • 8 comments

DELETE /Customers/{id}/thankBooks

  • This doesn't have filter

GET /Customers/{id}/thankBooks

  • This have filter

I think we need to apply filter for DELETE method instead of delete all records of related model.

bluestaralone avatar Oct 20 '14 04:10 bluestaralone

After find and research i found that:

  setRemoting(PersistedModel, 'destroyAll', {
    description: 'Delete all matching records',
    accepts: {arg: 'where', type: 'object', description: 'filter.where object'},
    http: {verb: 'del', path: '/'},
    shared: false
  });

Why do you need to set this remoteMethod is hidden ?

bluestaralone avatar Oct 22 '14 05:10 bluestaralone

@bajtos I have the same question and what do you think about this ?

projectxmaker avatar Oct 23 '14 02:10 projectxmaker

I don't know much about this part of loopback and loopback-datasource-juggler, @fabien or @raymondfeng are more suited to answer your questions.

bajtos avatar Oct 23 '14 16:10 bajtos

@bajtos thanks and wait for answer from @fabien or @raymondfeng ;)

projectxmaker avatar Oct 24 '14 01:10 projectxmaker

@bluestaralone Is that issue still relevant?

You can use

DELETE /Customers/{id}/thankBooks/{fk}

to delete a specific record of a thankBooks of the customer mode. let me know if that's not what you are looking for.

loay avatar Dec 02 '15 19:12 loay

@loay Arcording to your way, we just delete only one record, but my need is deleting multiple records.

bluestaralone avatar Dec 03 '15 01:12 bluestaralone

@bluestaralone I thought that's what you were looking for.

So basically the current workaround would be:

delete the whole records for customers would be:

DELETE /Customers/{id}/thankBooks

delete specific thankBooks with a specific ID:

DELETE /Customers/{id}/thankBooks/{fk}

delete multiple records of thankBooks with a specific condition:

PersistedModel.destroyAll([where], callback)

Another example from the documentation: https://docs.strongloop.com/display/public/LB/Where+filter#Wherefilter-Whereclauseforupdatesanddeletes

To delete all records where the cost property is greater than 100:

productModel.destroyAll( { cost: {gt: 100} }, function(err, obj) { ... } )

I guess you were looking to add the filter in the API explorer page, correct?

loay avatar Dec 03 '15 16:12 loay

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.

stale[bot] avatar Sep 06 '17 14:09 stale[bot]