简体   繁体   中英

EmberJS: Update multiple models on save

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.

There is didDelete on model so you should be able to do it there. That said, api that does not have integrity check is head scratching.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM