@johnnyicon (John) posted a new topic, subject "Ember Route cannot find model". It read:

   Hi all,
    
    I'm having an issue with loading a model into a route. This is a legacy app with some convoluted code, so I'll try to add some context to the situation so it makes sense.
    
    I'm trying to load an `organisational-unit` (UK spelling) into the `dashboard` route.
    
    ####  router.js
    [code] 
          this.route('producer', {path: '/orgs/:org_id'}, function() {
            this.route('dashboard');
          }
        
    [/code]
    
    ####  routes/producer/dashboard.js
    [code] 
          model(params) {
            return this.get('store').findRecord('organisational-unit', params.org_id);
          }
        
    [/code]
    
    The model `organisational-unit` exists.
    
    When I try to access the route `orgs/1/dashboard` as an example, I get the following error in the web console.
    [code] 
        -private.js:12702 Uncaught Error: No model was found for 'org'
            at Class._modelFactoryFor (-private.js:12702)
            at Class.modelFor (-private.js:12686)
            at InternalModel.get (-private.js:4543)
            at InternalModel.get (-private.js:4548)
            at Class._fetchRecord (-private.js:11366)
            at _fetchRecord (-private.js:11452)
            at Class._flushPendingFetchForType (-private.js:11553)
            at Map.forEach (<anonymous>)
            at Class.flushAllPendingFetches (-private.js:11430)
            at invoke (backburner.js:341)
        
    [/code]
    
    I thought that by specifying the `modelName` in `findRecord` would determine the model that would be used.
    
    Am I wrong? What should I be doing instead?
    
    Thanks in advance!

Then @ef4 (Edward Faulkner) said

    It sounds like the problem is not with the dashboard route that you showed, but with its parent route. The one that handles the `/orgs/1` part of the URL.

@sukima (Sukima) replied

    Because the param for `:org` is associated with the parent route the child route will not get the param by default. I just tested this in a twiddle and in your example the `dashboard` route will have `{ }` passed to its params. Instead you need to ask the parent for their params:
    [code] 
        // app/routes/producer/dashboard.js
        import Route from '@ember/routing/route';
        
        export default Route.extend({
          model(params) {
            console.log(params); // => { }
            let parentParams = this.paramsFor('producer');
            console.log(parentParams); // => { org_id: "1" }
          }
        });
        
    [/code]
    
    However, this is not the actual problem you are having because any route that has a dynamic segment that ends in `_id` will be assumed by Ember to be an ember-data model type. In your case a model of type `org`. It would seem the default route for a dynamic segment like this is to use ember-data to fetch the model type with that ID.
    
    To bypass this default behavior you will need to make a Route for `producer` and no-op its `model()` hook:
    [code] 
        // app/routes/producer.js
        import Route from '@ember/routing/route';
        
        export default Route.extend({
          model() { }
        });
        
    [/code]
    
    _(A Route without a`model()` hook defined is not enough.)_
    
    Once you have that then `this.paramsFor('producer').org_id` will be available to the `dashboard` route.

@johnnyicon (John) replied

    sukima:
    
    > this.paramsFor(‘producer')
    
    Thanks, @sukima! Your response was the solution.


{'source': 'discourse', 'url': 'https://discuss.emberjs.com/t/ember-route-cannot-find-model/16599', 'title': 'Ember Route cannot find model', 'views': 449, 'has_accepted_answer': False, 'word_count': 463, 'like_count': 1, 'reply_count': 1, 'participant_count': 3, 'posts': 4, 'tags': '', 'author': '@johnnyicon (John)', 'participants': '@johnnyicon (John), @ef4 (Edward Faulkner), @sukima (Sukima)', 'image_url': [None], 'created_at': '2019-05-27T23:41:43.308Z', 'last_posted_at': '2019-06-05T00:32:14.848Z'}