Skip to content

Suggestion for CRUD methods on the collection. #616

@CMCDragonkai

Description

@CMCDragonkai

I've read that the methods PUT, PATCH, DELETE does not exist on the collection object.

In the docs: https://github.com/mgonto/restangular#how-do-i-handle-crud-operations-in-a-list-returned-by-restangular

It demonstrates to get the collection first then work on the elements returned by that collection.

Another way is to instantiate a new object directly from Restangular by using Restangular.one('resource', id).

Both ways I feel is a bit inefficient. The first is in the 2 requests to do one thing, and the second while useful, doesn't allow me to share a single collection object.

What I'd really like to do is something like:

var collection = Restangular.all('accounts');
collection.get(4); //this already works
collection.remove(4); //this doesnt exist
collection.put(4, payload);
collection.patch(4, payload);
//...etc

The docs already state that you get an item off the collection by the id. Why not add all the other methods for consistency?

I know that remove currently exists, but not in a way that makes the above possible. Perhaps a bit more polymorphism on the functions that already exist would be suitable.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions