The code fix should probably be something like
case 'read':
if (model.idAttribute) {
if (model.attributes[model.idAttribute]) {
return MyAPI.find(model, success, error);
}
} else {
return MyAPI.findAll(model, success, error);
}
You need to test for both, because the model might define which attribute is it's id with the idAttribute
value, but the actual id value might not be present. In other words, if the model instance you receive is
{
idAttribute: "myId",
name: "test"
}
You can't call your find
method, because you have to id value to use in your query (i.e. myModel.get("myId")
wont return anything).