Note that there are some explanatory texts on larger screens.

plurals
  1. POIn latest Ember, how do you link to a route with just the id/name of a model, rather than providing all of its attributes in the linking page?
    primarykey
    data
    text
    <p>I ran into a problem when converting from Ember 1.0-pre2 to latest master (<a href="https://github.com/emberjs/ember.js/commit/43354a98a5e441095132b1407f3e1f4809326802">43354a98</a>) and the new router, namely--</p> <p>If I have a route which loads just the name and ID for a bunch of records, and tries to link each of those records to another route which should display the full model, when I arrive at the new route, the new model is never loaded, and name and ID are the only attributes that are available.</p> <p>Example code:</p> <pre><code>App.Router.map(function() { this.route("index"); this.resource("birds"); this.resource("bird", { path: "/birds/:bird_id" }); }); App.BirdsController = Ember.ArrayController.extend({ birds: [ { name: "Pigeon", id: "b.15" }, { name: "Chicken", id: "b.133" }, { name: "Turkey", id: "b.126" }, { name: "Ostrich", id: "b.4" }, { name: "Barn Owl", id: "b.47" } ] }); App.BirdRoute = Ember.Route.extend({ model: function(params) { return App.Bird.find(params.bird_id); } }); {{#each bird in birds}} &lt;li&gt;{{#linkTo "bird" bird}}{{bird.name}}{{/linkTo}}&lt;/li&gt; {{/each}} </code></pre> <p>where App.Bird.find() runs some XHR's to build up an Ember.Object from a set of remote API's (not using ember-data). The list of birds is hardcoded into the controller just for this example, to simplify the issue; in my real application, the list is coming from a remote API.</p> <p>The behavior I'm seeing is that if you start on /birds and click one of the links, the router transitions to 'bird' and you arrive on /#/birds/b.5, but App.Bird.find() is never called, and the only data I have on the page are "name" and "id". However, if you then reload the page, it does call App.Bird.find() and properly builds up and displays the model.</p> <p>Is there some way to force deserialization from the ID in the URL, or to just pass an ID to linkTo rather than an object that it will assume is complete? I had an analogous implementation working fine with the old router.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload