Closed damionvega closed 9 years ago
Looking at the source, this appears to happen if it thinks the model is new, i.e. if model[model.idAttribute]
(in this case model._id
) is falsey.
Can you log out category.isNew()
and category.toJSON()
in your deleteCategory
function?
Yeah that looks like the case. I was looking for this in the documentation, but it seems it was removed? Here's the link on ampersandjs.com under ampersand-model -> destroy: http://ampersandjs.com/docs#ampersand-model-isnew
Here's the output:
categories.jsx:72 category.isNew()
true
categories.jsx:73 category.toJSON()
Object {_id: "AU_TyfmweKF7y9ngEHq7", name: "computer", tags: Array[3]}
After adding idAttribute: '_id'
to the model, DELETE xhr is made and model removed from collection:
category.isNew()
false
categories.jsx:73 category.toJSON()
Object {_id: "AU_TyfmweKF7y9ngEHq7", name: "computer", tags: Array[3]}
categories.jsx:77
category destroyed!
So use idAttribute
if you plan on using that model for persistence and mainIndex
for collection tracking (if your ID !== id
)?
Thanks for your help!
mainIndex is for checking for existing copies of yourself in ampersand-collection
and defaults to the idAttribute
if I remember correctly
The model is removed from the collection when
category.destroy()
is invoked, yet no xhr request is made.Here's the console output,
res
is undefined