Remove a foreign record (e.g. a comment) from one of this record's collection associations (e.g. "comments").
DELETE /:model/:id/:association/:fk
This action removes a reference to some other record (the "foreign" record) from a collection attribute of this record (the "primary" record). Note that this does not actually destroy the foreign record-- it just removes it.
Parameter | Type | Details |
---|---|---|
model | The identity of the containing model for the parent record. e.g. 'store' (in /store/16/employeesOfTheMonth/7 ) |
|
id | The desired target record's primary key value e.g. '16' (in /store/16/employeesOfTheMonth/7 ) |
|
association | The name of the collection association e.g. 'employeesOfTheMonth' |
|
fk | The id of the foreign record to remove from the collection association. e.g. 7 |
|
callback | If specified, a JSONP response will be sent (instead of JSON). This is the name of the client-side javascript function to call, passing results as the first (and only) argument e.g. ?callback=myJSONPHandlerFn |
Say you're building an app for a small chain of grocery stores. Each store has a giant television screen that displays the current "Employee of the Month" at that store, so that customers and team members see it when they walk in the door. In order to be sure it is up to date, you build a scheduled job (e.g. using cron) that runs on the first day of every month to change the "Employees of the Month" for each store in our system.
Let's say that, as a part of this scheduled job, we send a request to remove Dolly (employee #7) from the employeesOfTheMonth
list of store #16:
DELETE /store/16/employeesOfTheMonth/7
{
"id": 16,
"name": "Parmer and N. Lamar",
"createdAt": "2014-08-03T01:16:35.440Z",
"updatedAt": "2014-08-03T01:51:41.567Z",
"employeesOfTheMonth": []
}
- If you'd like to spend some more time with Dolly, a more detailed walkthrough for the example above is available here.
- This action is for dealing with plural ("collection") associations. If you want to set or unset a singular ("model") association, just use update and set the model association to the id of the new foreign record (or
null
to clear the association).