5

Lets say I have a Customer who hasMany products

The api has a PUT: /customers/:id/cancel that cancels the customer and also cancels all the products and then returns the customer and the products for sideloading:

{
  customer: {
    id: 1,
    name: "Customer Name",
    canceled: true,
    products: [1, 2] },

  products: [
    {id: 1, customer_id: 1, name: "Product 1", canceled: true},
    {id: 2, customer_id: 1, name: "Product 2", canceled: true}
  ]
}

how would I:

  1. Call that action on the customer?
  2. Update all objects in the Ember Store?
Kim Fransman
  • 145
  • 2
  • 6

1 Answers1

1

For part 1. of your question,

  • You'll want to find it in the store var customer = store.find('customer', 1);
  • Then tell it to delete customer.destroyRecord();
  • And finally commit the delete customer.save();

For part 2. deleting the products, you'll have to do delete them manually in a forEach loop, tucked inside an Ember.run.once., as there is no cascading delete in ember data at this stage of the game.

Here is an example of this for a top level delete, so you would need to follow the same logic but for your products and follow it up with a .then that deletes your connected customer.

Hope that gets at what you were asking. Cheers!

Community
  • 1
  • 1
Eric D. Johnson
  • 10,219
  • 9
  • 39
  • 46