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

Multiple nested models in one route

$
0
0

@brownie3003 wrote:

I'm building a quoting tool at the moment. I'm struggling with how to load nested models with only one parent route. My quote is a document. Each document has many sections and each section has many lineItems. The caveat is that I want my route to be /documents/123, and for that route to show the document with all it's sections and all of the lineItems. I started by making a route for document.show:

Router.map(function() {
    this.route('documents', function() {
        this.route('show', { path: ":document_id"});
    });
});

In this route I started loading the document:

export default Ember.Route.extend({
    model(params) {
        return this.get('store').findRecord('document', params.document_id);
    }
});

Then I needed to get all the sections for the document, so I did this:

export default Ember.Route.extend({
    model(params) {
        return RSVP.hash({
            document: this.get('store').findRecord('document', params.document_id),
            sections: this.get('store').findRecord('document', params.document_id).then((document) => {
                return document.get('sections');
            })
        });
    }
});

Then I needed to get all the lineItems for each section... at which point I felt like I wasn't approaching the problem in the 'ember' way, as it felt really awkward.

I've read this article about making components load their own data: http://forspareparts.github.io/2016/01/24/actions-up-data-sideways/. It's a solution I thought about implementing, but I don't know if it's a good solution?

Basically looking for advice from more experienced Ember devs on how you would handle this situation. I can't find any resources online that cover this situation, maybe I'm looking in the wrong places.

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 4828

Trending Articles