Note that there are some explanatory texts on larger screens.

plurals
  1. POdeleteRecord doesn't update ArrayController when Model is filtered
    primarykey
    data
    text
    <p>I am using a simple <code>Ember.ArrayController</code> in an application with <code>ember-data</code> (latest), <code>ember rc6</code> and a stock REST controller.</p> <p>I have delete actions next to each item in the list rendered by the array controller. When an item is deleted, the proper REST API call is made and it's removed from the database properly. Server responds with the correct <code>204</code> response.</p> <p>Here is my router setup, notice the find filter being applied</p> <pre><code>App.CategoriesIndexRoute = Ember.Route.extend({ setupController : function(controller, model) { this._super(controller, model); controller.set("content", App.Category.find({ "parent": null, })); } }); </code></pre> <p>If I remove the find filter and load all categories, everything works fine (item is automatically removed from the list immediately after commit). However, when I add the filter to only display categories that don't have a parent, the list is not updated when an item is deleted. If I transition to another section and come back, the list is reloaded and the category is gone.</p> <p>Here is <code>deleteCategory</code> method in the <code>ArrayController</code>:</p> <pre><code>deleteCategory: function(category) { var transaction = this.get("store").transaction(); transaction.add(category); category.deleteRecord(); transaction.commit(); } </code></pre> <p>Is this an <code>ember-data</code> or <code>emberjs</code> bug? If not, what am I doing wrong here? If it's a bug, is there a way to force-reload the ArrayController contents after I delete an item? Alternatively, can I remove the category from the ArrayController manually?</p> <p>UPDATE 1:</p> <p>I managed to force-update the array controller's contents by setting its content:</p> <pre><code>category.one("didDelete", this, function() { this.set("content", App.Category.find({ parent: parent_category })); }); </code></pre> <p>UPDATE 2:</p> <p>Here is how I am displaying the list of items in the template:</p> <pre><code>{{#each category in controller.content }} &lt;tr&gt; &lt;td&gt;&lt;a {{ action "detailCategory" category }}&gt;{{ category.name }}&lt;/a&gt;&lt;/td&gt; &lt;td&gt;&lt;a {{ action "deleteCategory" category }}&gt;Delete&lt;/a&gt;&lt;/td&gt; &lt;/tr&gt; {{/each}} </code></pre> <p>Thank you!</p>
    singulars
    1. This table or related slice is empty.
    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.
    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