Looking for some advice on the best way to update multiple models on save. Why might I want to do this, you ask? Well, I'm using Parse as my backend and unfortunately relationships are only one way. In order for them to work in Ember, I need to manually manage pointers.
Example: Obj A belongs to Obj B. Obj B has many Obj As. Parse stores a pointer from Obj B to Obj A, but I need to store an array of objects in Obj B that contains IDs for all of the Obj As. When I go to delete an Obj A, I need to save Obj B with the updated array of As. Currently, I'm doing something like this in my component logic:
ObjA.save().then(() => {
ObjB.save();
});
That seems to work, but I'd like to move this logic to the adapter so I don't have to think about it every time I'm deleting (or adding) a new object.
I was thinking I could find a hook somewhere in the adapter to check if if an object is being deleted. If so, send a PUT request to ObjB with the new list of ObjAs. I just need some guidance figuring out where that would go. Or, maybe the best way is to handle this in each component.
Aucun commentaire:
Enregistrer un commentaire