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 docs don't mention how to find/fetch polymorphic #5246

Closed
BryanCrotaz opened this issue Oct 30, 2017 · 5 comments
Closed

polymorphic docs don't mention how to find/fetch polymorphic #5246

BryanCrotaz opened this issue Oct 30, 2017 · 5 comments
Labels
🏷️ doc This PR adds/improves/or fixes documentation

Comments

@BryanCrotaz
Copy link
Contributor

Would expect to see how to find/fetch exactly my-model or my-model and all its descendants.

@smackesey
Copy link

Agreed -- they're also unclear on whether you have to do anything special with JSONAPI:

Note that, for polymorphism to work, Ember Data expects a "type" declaration polymorphic type via the reserved type property on the model. Confused?

I can't make head or tail of this sentence. Do I somehow have to mark types polymorphic with JSONAPI, or it enough that they just have a particular relationship?

@runspired
Copy link
Contributor

Yeah that sentence is pretty awful :(

Roughly speaking, always give the most specific type possible to any resource your API returns.

For instance, if dog extends pet, return dog not pet. ember-data would consider dog:1 and pet:1 to be separate entities if you were to return both, and any relationships would become weirdly broken.

@anlumo
Copy link

anlumo commented Jul 22, 2018

My serializer needs the following code for my polymorphic relationship props to work:

  serialize(snapshot, options) {
    let result = this._super(...arguments);
    let props = snapshot.hasMany('props');
    if(props) {
      result.props = props.map(prop => ({
        id: prop.id,
        type: prop.modelName,
      }));
    }
    return result;
  },

Loading using pushPayload does work automatically. I'm using the JSON serializer.

@runspired
Copy link
Contributor

We're working on some big improvements to polymorphism that were unlocked by the relationship-refactor work and the identifiers work. The intent is to RFC an official polymorphism feature (polymorphism has mostly been undocumented because it never was fully designed) and we'll be sure to add a polymorphic guide at that time.

Until then, I'll see if we can get some small docs updates done to illuminate how the current setup works.

@runspired
Copy link
Contributor

Explicit relationship polymorphism is now in place, polymorphic find was described by the identifiers RFC (though showing a basic config in the guides would be nice too). Polymorphic find is also covered by the RequestManager, since it is agnostic to type.

Broadly speaking, most things in EmberData are agnostic to type at this point, most polymorphic cases should "just work" excepting those in which you refer to the same resource by multiple identities, in which case you will need to configure the IdentifiersCache to be able to know that these identities refer to the same resource.

Closing in favor of the documentation quest in #8394

@runspired runspired added 🏷️ doc This PR adds/improves/or fixes documentation and removed Documentation labels Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ doc This PR adds/improves/or fixes documentation
Projects
None yet
Development

No branches or pull requests

4 participants