strongloop / loopback

LoopBack makes it easy to build modern applications that require complex integrations.
http://loopback.io
Other
13.23k stars 1.2k forks source link

Inconsistent between GET and DELETE on related models #665

Closed bluestaralone closed 7 years ago

bluestaralone commented 10 years ago

DELETE /Customers/{id}/thankBooks

GET /Customers/{id}/thankBooks

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

bluestaralone commented 10 years ago

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 ?

projectxmaker commented 9 years ago

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

bajtos commented 9 years ago

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

projectxmaker commented 9 years ago

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

loay commented 8 years ago

@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.

bluestaralone commented 8 years ago

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

loay commented 8 years ago

@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?

stale[bot] commented 7 years ago

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.