@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
. Eachdocument
has manysections
and eachsection
has manylineItems
. The caveat is that I want my route to be/documents/123
, and for that route to show thedocument
with all it'ssections
and all of thelineItems
. 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 eachsection
... 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