Supplying models to transitions

I’m running into problems with links and transitions in the latest build of Ember.js (I just came from RC6, so this might be a simple fix). Whenever I supply a model to a link-to helper or the transitionTo function, Ember routes to the correct page, but the ID of the model is undefined in the URL (making it impossible to refresh). But when I use just the ID, it works fine. For instance, I have this afterModel hook:

afterModel: function(resolvedModel, transition, queryParams) {
    if (resolvedModel.get('length') === 1) {
        this.transitionTo('organizations.organization.index', resolvedModel.get('firstObject'));
    }
}

When the transition happens, it takes me to the correct page, but the URL comes out as /organizations/undefined. However, if I add .get('id') onto the second parameter and pass just the ID instead of the whole model, the ID comes out as it should: /ogranizations/ORG_1. The same thing happens when using a link-to helper.

Is this a bug, or just a feature of the 1.0 release? In RC6, I was definitely able to pass the model and not just the ID.

Have a look at the Ember.Route serialize documentation. Is that what you’re looking for?

I’m sorry, I got this answered on StackOverflow yesterday and forgot to update this. Yes, the serialize method was what I was looking for. My problem was that I was using organizationId as the dynamic segment instead of organization_id. The confusion came here (from the guide on routing):

The default serialize method inserts the model’s id into the route’s dynamic segment

It made it seem as if the router would insert the ID into any dynamic segment, when in reality, it will only insert it into a dynamic segment that ends with _id. I thought it was a bit confusing myself, but maybe I’m just not too bright. :smile: