genkgo / ember-localforage-adapter

Offline usage for Ember Data, based on localstorage adapter, but now uses Mozilla's localforage as data source
Other
133 stars 26 forks source link

Polymorphic belongsTo #82

Open NullVoxPopuli opened 5 years ago

NullVoxPopuli commented 5 years ago

Not sure if this'd be solved in adapter-space, or if I've configured something wrong. But I have the following models:

Identity

export default class Identity extends Model implements Partial<PublicKey> {
// ...
}

User

export default class User extends Identity implements Partial<KeyPair> {
  @attr() privateKey!: Uint8Array;
}

Contact

export default class Contact extends Identity {
  @attr() onlineStatus?: STATUS;
}

Message

export default class Message extends Model {
  @belongsTo('identity', { async: false, polymorphic: true }) sender?: Identity;
}

My Adapter and Serializer config:

import LFAdapter from 'ember-localforage-adapter/adapters/localforage';

export default LFAdapter.extend({
  caching: 'none',

  shouldBackgroundReloadRecord() {
    return true;
  },

  shouldBackgroundReloadAll() {
    return true;
  },
});

import LFSerializer from 'ember-localforage-adapter/serializers/localforage';

export default LFSerializer;

The problem I'm having is that I have a Message with sender id of a contact.

image

Here is the current state of indexeddb image so, it looks like the relationship information in localforage loses the type.

I almost wonder if this adapter should just use jsonapi for storage, since it's the most semantically correct for relational data.

NullVoxPopuli commented 5 years ago

Yeah, jsonapi is the one true way. image

all the information is just right there :)

Just need to figure out how to get serialization and deserialization working better.

On the plus side, with jsonapi, we can delete the serializer for localforage-adapter :)