Closed ivan-kleshnin closed 9 years ago
From what I understand you want to completely clear your collection on the client-side and get up to date data from the server?
var Photos = AmpersandRestCollection.extend({ url: '/photos' });
var photos = new PhotosCollection();
photos.add([{ ... })]; // let's say you've added something, but you want to get rid of it and fetch data from server
photos.fetch({
reset: true // <= this will reset entire collection before putting your data in it
});
Is that what you wanted to achieve?
No, I want to clear data on client and (as a consequence) remove it on server. In conventional way.
From what I'm seeing, there is no built-in way to do a batch delete. You'd need implement that in your collection definition. The sync
method is a low-level method that is used by fetch
, getOrFetch
, and fetchById
. If called directly, it should be called with request type (one of: create, read, update, delete, patch), the collection, and options object (optional).
I speculate that that batch delete has been left out since how to do it is highly dependent on what the server-side makes available for that purpose.
Thank you, I'll give it a second look.
I don't understand how it should be implemented. Manually (iterate and
model.save
/model.destroy
one by one) or via some existing method?There are something called "sync"
which is entirely undocumented and I had no luck trying to run this. Even its signature looks broken (this is a quote from "ampersand-rest-collection" doc link so it ought to be
collection.sync(...)
at least!)I thoroughly reviewed to this moment:
Someone states that this is low-level method and it should not be used for basic tasks. However the question remains. Basically I expected to empty entire collection on client and remove corresponding data on server by issuing next commands:
Technically, resulting error from the second line is
but this is obviously due to wrong arguments. By Backbone docs it looks like it should be called like
which is totally bizarre. So I surrender and ask for help.