New serializer API: why isn't the relationship being restored?


#1

I’m trying to bring the local-storage-adapter plugin up to 1.13 and i’m encountering a problem. For some reason when i return a specific jsonapi style response from normalizeSingleResponse ember fails to recover the relationships properly. It only fails on 1 single test so far.

EDIT: I can confirm that it is because the reflexive relationship is not present. Is this a bug?

The only thing i can see is that the reflexive relationship is not also present in the JSON response but it wouldn’t be since the test only saved the item object and not the list object.

In the code below the call to item.get('list'); returns null after the debugger statement.

test('saves belongsTo', function() {
  var item,
      listId = 'l2';

  stop();
  store.findRecord('list', listId).then(function(list) {
    item = store.createRecord('item', { name: 'three thousand' });
    item.set('list', list);

    return item.save();
  }).then(function(item) {
    store.unloadAll('item');
    return store.findRecord('item', item.get('id'));
  }).then(function(item) {
    // TODO: THIS IS NOT RECOVERING THE LIST.
    debugger;
    var list = item.get('list');
    ok(item.get('list'), 'list is present');
    equal(list.id, listId, 'list is retrieved correctly');
    start();
  });
});

Here is what the return from normalizeSingleResponse on the return store.findRecord('item', item.get('id'));

{
    "data":{
         "id":"eup8h",
         "type":"item",
          "attributes":{
                "name":"three thousand"
          },
      "relationships":{
             "list":{
                 "data":{
                     "id":"l2",
                     "type":"list"
                  }
               }
       }
   },
   "included":[
         {
             "id":"l2",
              "type":"list",
               "attributes":{
                  "name":"two",
                   "b":false
                },
               "relationships":{
                      "items":{
                           "data":[
                             ]
                       }
               }
          }
     ]
}

When i go into item._internalModel._relationships.initializedRelationships.list.canonicalState.id i get null when i hit canonicalState