Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove a backbone model by id?

Tags:

Can you remove a model by id? The documentation says you need to pass in the model itself to remove it.

So I need to fetch the model first and then remove it? I can't just remove it by id?

like image 840
fancy Avatar asked May 01 '12 16:05

fancy


1 Answers

Do you mean remove the model from a collection? Looking at the docs, it does seem like you need to pass in a real model, but the source code suggests that you can just pass in either the model id or the model cid as well, and all of the above should work (as well as arrays of all of the above).

So all of the following should be equivalent:

collection.remove(myModel); collection.remove(myModel.id); collection.remove(myModel.cid); collection.remove([myModel]); 

I haven't tested this, however.

like image 154
nrabinowitz Avatar answered Oct 07 '22 22:10

nrabinowitz