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

Embeded relationship data not loading #16

Open
Subaku opened this issue Dec 12, 2019 · 10 comments
Open

Embeded relationship data not loading #16

Subaku opened this issue Dec 12, 2019 · 10 comments

Comments

@Subaku
Copy link

Subaku commented Dec 12, 2019

Hello,

Have an issue I don't understand. I've an Ember-Data model, AssetLocation that has several belongsTo relationships. I can get one relationship to load data but the others don't. I confirmed that the mirage server is creating the data behind the scenes so I think this is a config or serialization issue.

Here's my Mirage serializer for the model.

import ApplicationSerializer from './application';

export default class AssetLocationSerializer extends ApplicationSerializer {
  root = false;
  embed = true;
  include = ['location', 'asset', 'assignedTo', 'seenBy'];
}

Here the actual Ember-Data serializer for the same model.

import DS from "ember-data";
import ApplicationSerializer from './application';

const { EmbeddedRecordsMixin } = DS;


export default class AssetLocationSerializer extends ApplicationSerializer.extend(EmbeddedRecordsMixin) {
  attrs = {
    asset: { embedded: 'always' },
    assignedTo: { embedded: 'always' },
    location: { embedded: 'always' },
    seenBy: { embedded: 'always' },
  }
}

Here's a sample request made from my app.
image

The embedded assets get created just fine. It's the others that don't. So assignedTo and seenBy for example never get created in the store. Am I missing something here?

@samselikoff
Copy link
Contributor

First I would not use ES6 classes because Mirage isn't designed to work with them yet.

Second, just to clarify what are you expecting assignedTo to be in the screenshot?

@Subaku
Copy link
Author

Subaku commented Dec 14, 2019

Thanks for getting back to me.

  1. I'll make all the changes so my Mirage stuff isn't using ES6 classes. Make double sure that's not causing me any grief.

  2. The assignedTo, location, and seenBy are all belongsTo relationships to the same model called "place". From what I can tell I've mimicked how I handled another model with a belongsTo to the same model.

Once I make the ES6 class corrections I'll let you know if that test does anything.

@Subaku
Copy link
Author

Subaku commented Dec 16, 2019

Just switched my Mirage Serializers to not use ES6 classes. Get the same results as before unfortunately.

@samselikoff
Copy link
Contributor

@Subaku Sorry you're still having trouble.

Could you write out the exact JSON you're expecting to be returned from GET /api/v1/asset-location/?location=3?

@samselikoff
Copy link
Contributor

Even better would be to share a reproduction of the issues – that's usually the fastest way to get help!

@Subaku
Copy link
Author

Subaku commented Dec 19, 2019

Here's a repo with a slimmed down version of my app that should replicate my issue.
https://github.com/Subaku/mirage-issue.git

I ultimately suspect I've just neglected to declare or configure something...
Thanks for your help!

@samselikoff
Copy link
Contributor

So sorry for the delay! Busy holiday season.

Looks like you're just requesting all asset-location-summary models, and those only have one association, location, which is a Place model. Place only has 5 attrs, all of which are included.

So if you want the rest of the data you'll need to change your query. What data are you trying to get?

@Subaku
Copy link
Author

Subaku commented Jan 6, 2020

No worries. Hope your holiday was good :)

I was attempting to get all related fields back as embedded records. In my screenshots above both location and assignedTo are related to the Place model but are different Place records. I was expecting both to be included in the response given the configuration I had set on the Mirage AssetLocationSerializer. The embed and include to be precise. Given how my APIs function I may just be misunderstanding how things function here.

@samselikoff
Copy link
Contributor

In your demo app the URL requested is for all asset-location-summary models. And I think Mirage is returning the whole graph, which just consists of asset-location-summary and the associated location.

Are you saying if you were to request asset-location model it's not including the other related models? If so could you update the app with the request you're having trouble mocking?

@samselikoff samselikoff transferred this issue from miragejs/ember-cli-mirage Jan 30, 2020
@samselikoff
Copy link
Contributor

FYI: Transferred this to our Discuss repo, our new home for more open-ended conversations about Mirage!

If things become more concrete + actionable we can create a tracking issue in the main repo.

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

No branches or pull requests

2 participants