Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat's the right way to delete a record in Ember Data revision 12?
    primarykey
    data
    text
    <p>I'm using revision 12 of Ember Data.</p> <p>I've got a simple method on an <code>ArrayController</code> that tries to delete a single record, and is called from an action in a template:</p> <pre><code>deleteFact: function(fact) { self=this; window.App.confirm(Em.I18n.t('Delete fact?'), { yes: function() { fact.deleteRecord(); fact.store.commit(); } }); } </code></pre> <p>This always works with the first record deleted, and the list shows the record disappears. I'm using Rails, and the server processes the <code>DELETE</code> and returns a JSON empty object and <code>status 200</code>. If I delete another record any time after that first delete I always get an internal exception thrown immediately:</p> <p><code>Uncaught Error: Attempted to handle event</code>deleteRecord<code>on &lt;App.Fact:ember402:31&gt; while in state rootState.deleted.saved. Called with undefined</code></p> <p>What's the right way to delete a record. I've searched Google and can't find any answers, and the source code and tests for ember data look like this is all that has to be done. </p> <p>Template:</p> <pre><code>{{#each fact in content}} &lt;tr&gt; &lt;td&gt;{{fact.title}}&lt;/td&gt; &lt;td&gt;{{fact.body}}&lt;/td&gt; &lt;td&gt;{{#linkTo 'facts.show' fact}}View{{/linkTo}} | &lt;a {{ action 'deleteFact' fact}} class="button small deny delete-button"&gt;Delete&lt;/a&gt;[{{fact.id}}]({{fact.stateManager.currentState.path}})&lt;/td&gt; &lt;/tr&gt; {{else}} &lt;tr&gt; &lt;td colspan='4'&gt;No facts registered at present.&lt;/td&gt; &lt;/tr&gt; {{/each}} </code></pre> <p>Template Output:</p> <pre><code>Title Facts Actions asdfsd asdfsadf View | Delete[46](rootState.loaded.saved) asdfsd asdfsadf View | Delete[47](rootState.loaded.saved) asdfsd asdfsadf View | Delete[48](rootState.loaded.saved) </code></pre> <p>Output in Console:</p> <p>Clicking delete on record with Fact Id 46 logs to console from the yes function that id 46 was passed. Record disappears from list displayed by template, leaving two records with id 47, and 48. Clicking delete for record 47 shows in log that record id 46 was passed again.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload