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

Best way to load nested models #256

Open
srsgores opened this issue Mar 19, 2020 · 1 comment
Open

Best way to load nested models #256

srsgores opened this issue Mar 19, 2020 · 1 comment

Comments

@srsgores
Copy link

Confused about the best way to load nested models (parent models which have one or more hasMany relationships). For example:

Project > Timeline > Node > Timeline > etc.

Currently, with ember data's async: true behaviour, any nested model does not load, even if accessed from the template:

{{@timeline.id}}

Where timeline.id renders as expected when the child timeline is first created, but subsequent loads fail in the route via this query:

model(params) {
	return this.store.findRecord("project", params.project_id);
};

Where the model looks like this:

(models/project.js)

import {belongsTo, attr} from "@ember-data/model";
import {Model} from "ember-pouch";

export default class ProjectModel extends Model {
	@attr name;
	@attr description;
	@belongsTo("timeline") timeline;
}

(models/timeline.js)

import {hasMany, belongsTo, attr} from "@ember-data/model";
import {Model} from "ember-pouch";

export default class TimelineModel extends Model {
	@belongsTo("project") project;
}

In the ember docs, they mention JSON-API's include parameter, which isn't available for ember-pouch users as far as I can tell. What method is suggested for loading asynchronous, nested relationships?

@jlami
Copy link
Collaborator

jlami commented Mar 19, 2020

I don't understand why a belongsTo would not load with async: true. This should work:

{{project.timeline.name}}

The route not loading the model you request should not be related to async.
You also mention hasMany but don't have any in your examples. Could you clarify your problem?

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

2 participants