Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polymorphic belongsTo #82

Open
NullVoxPopuli opened this issue May 11, 2019 · 1 comment
Open

Polymorphic belongsTo #82

NullVoxPopuli opened this issue May 11, 2019 · 1 comment

Comments

@NullVoxPopuli
Copy link

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
Copy link
Author

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant