locks / ember-localstorage-adapter

Name says it all.
MIT License
465 stars 156 forks source link

Relationships to a model using another adapter #163

Closed esistgut closed 5 years ago

esistgut commented 8 years ago

I have a "local-service" with a relationship to "service". If I try to query the first one I get this:

$E.store.query('local-service', {ready: 'detail'});
Class {__ember1461680620095: null, __ember_meta__: Meta}
ember.debug.js:32127 Error: Couldn't find record of type 'service' for the id '1'.
    at findRecord (ls-adapter.js:51)
    at ls-adapter.js:336
    at tryCatch (ember.debug.js:53546)
    at Object.invokeCallback (ember.debug.js:53561)
    at ember.debug.js:55687
    at ember.debug.js:32085
    at Queue.invoke (ember.debug.js:333)
    at Object.Queue.flush (ember.debug.js:397)
    at Object.DeferredActionQueues.flush (ember.debug.js:205)
    at Object.Backburner.end (ember.debug.js:560)

but the service model is working fine on his own:

$E.store.query('service', {id: 1});
Class {__ember1461680620095: null, __ember_meta__: Meta}

This is the relevant dump of my localstorage:

{
   "local-service":{
      "records":{
         "7usvd":{
            "id":"7usvd",
            "hashId":"1",
            "parentHashId":null,
            "quantity":1,
            "ready":"detail",
            "required":true,
            "options":{
               "adults":3,
               "children":0,
               "datetime":"2016-04-26T22:00:00.000Z"
            },
            "service":"1"
         },
         "vtd3u":{
            "id":"vtd3u",
            "hashId":"1.roundTrip",
            "parentHashId":null,
            "quantity":1,
            "ready":"detail",
            "required":true,
            "options":{
               "adults":3,
               "children":0,
               "datetime":null
            },
            "service":"4"
         }
      }
   }
}

and this is the local model:

import DS from 'ember-data';

export default DS.Model.extend({
  hashId: DS.attr('string'),
  parentHashId: DS.attr('string'),
  service: DS.belongsTo('service'),
  quantity: DS.attr('number'),
  ready: DS.attr('string'),
  required: DS.attr('boolean'),

  options: DS.attr('jsonfield')
});

The service model uses an adapter built on top of the rest adapter. I am using ember-cli@2.5.0, ember-data@2.5.2 and ember-localstorage-adapter@1.0.0-rc.1.

What am I doing wrong?

vclayton commented 6 years ago

I think this behavior was broken by https://github.com/locks/ember-localstorage-adapter/commit/c34acd786633ae96f7ddfb211f630bac3aa255b2

The change from using === to using DS.LSAdapter.prototype.isPrototypeOf was great, but it should still have been looking at foreignAdapter. That var got removed in a later cleanup step since it didn't appear to be used, but it needs to go back in: var foreignAdapter = store.adapterFor(relationModel);