Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4837

Force Load Ember Data Relationship

$
0
0

@niltz wrote:

I have an ember data model that looks like this (note that I am using typed-ember/ember-cli-typescript)

import DS from "ember-data";

export default class AccountIdentity extends DS.Model.extend({
  organizations: DS.hasMany("org/organization", { async: true })
}) {
  // normal class body definition here
}

// DO NOT DELETE: this is how TypeScript knows how to look up your models.
declare module "ember-data/types/registries/model" {
  export default interface ModelRegistry {
    "account/identity": AccountIdentity;
  }
}

Then I load my account/identity like so:

const identity = this.store.findRecord("account/identity", "abc")

Which calls the api, and the api returns:

{
    "data": {
        "type": "account/identities",
        "id": "abc"
    }
}

Note how the response doesn’t contain any organization relationships, and this is because they are on a different service and the account service doesn’t know anything about the org service. But I was hoping i could override the urlForFindHasMany and tell ember data where to load the organizations from. However when I do:

const organizations = await identity.get("organizations");

My urlForFindHasMany method isn’t called, nor is any other API call of any kind. How can I tell/force ember data to load the relationship data?

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4837

Trending Articles