RESTAdapter nested hasMany doesn't refresh data properly


#1

I’ve been struggling for awhile trying to get this working, and was hoping that there might be someone on this forum who could help me.

I am not sure if this is a known ember-data bug or if I am doing something wrong.

In my application I display a list of folders => GET /folders

Clicking on a folder causes a list of items which belong to that folder to be displayed in a second list => GET /folders/folder_id/items

Clicking on one of these items displays a list of key-value pairs belonging to that item => GET /folders/folder_id/items/item_id/keys

Each folder has zero or more items and each item has zero or more keys, from left to right a hasMany relationship and from right to left a belongsTo relationship.

Here is what the data model looks like:

App.Folder = DS.Model.extend({
    name: DS.attr('string'),
    items: DS.hasMany('item', {async: true} )
});

App.Item = DS.Model.extend({
    name: DS.attr('string'),
    folder: DS.belongsTo('folder', {async: true} ),
    keys: DS.hasMany('key', {async: true} )
});

App.Key = DS.Model.extend({
    name: DS.attr('string'),
    value: DS.attr('string'),
    item: DS.belongsTo('item', {async: true} )
});

Here’s the weird part. As I start at the top of the items list and click each item from top to bottom, the first time a GET request is issued and the response is displayed properly: key-value pairs are shown in the list.

However, if I go back to the top item (or to any other item that has already been clicked) no keys are displayed anymore, only from the last item I clicked that resulted in a GET request.

A GET request is only issued once the first time (expected behavior of course).

This does not occur for the folders list, each click displaying all of the items in the list correctly,

If I use fixture data then this problem does not appear anymore.

Does this make sense and is there a solution?

DEBUG: -------------------------------
DEBUG: Ember      : 1.8.1
DEBUG: Ember Data : 1.0.0-beta.11
DEBUG: Handlebars : 1.3.0
DEBUG: jQuery     : 1.10.2
DEBUG: -------------------------------

#2

I don’t know for sure but to me it seems the hasMany bug is in Ember-Data and not in the Adapters. See also https://github.com/emberjs/data/issues/2494#issuecomment-66863994


#3

Well if it indeed is a bug in ember-data then I’d expect it also to be a problem with fixtures, but with fixtures my application works perfectly fine.