Undefined properties in Route#serialize?

Okay, I’ll give a quick run down of the issue. And an ember data expert is more than welcome to correct me if I’m wrong, because I don’t use ember data. It appears that belongsTo and hasMany aren’t resolved synchronously. They are materialized asynchronously later. Unfortunately, the serialize method is run once, it doesn’t depend on any property, and doesn’t go around changing itself. Really it’s meant to give the parameters for returning to that particular model. That being said, I recommend using fix one, because it more truly represents your model (having the group name in the url doesn’t nothing for looking up that models data).

Fix one

http://jsbin.com/imakeg/8/edit

I do understand that maybe this jsbin doesn’t fully show your issue at hand, so I propose fix two. Since the materialization isn’t done right off the bat, you can cheat, and find the suggestion models before the suggestiongroup models and then the materialization will black magically happen before your serialization method and give you the url you are looking for. (I don’t like this, very hacky in my opinion)

Fix two

http://jsbin.com/imakeg/12/edit

And then there is option 3. Change your template so instead of using the linkTo, use an action. Then serialization is out of the picture and you rely on transitionTo (which will serialize correctly) and you could also send in multiple models if applicable. I still like #1 the most, but best of luck either way.

Fix three

http://jsbin.com/imakeg/11/edit

1 Like