ember.js - Getting ID of Parent Object in Route -
i have ember 1.11 app created ember-cli 0.2.3. have following in router.js file:
this.route('ownedgames', function() { this.route('gameplays', {path: ":owned_game_id/plays"}, function() { }); });
this allows me use following url:
http://localhost:4200/ownedgames/1/plays
when visit url, getting following error:
uncaught error: assertion failed: value #each loops on must array. passed '<ember-bgg@model:owned-game::ember470:1>' (wrapped in (generated ownedgames.gameplays controller))
here route gameplay
import ember 'ember'; export default ember.route.extend({ model: function(params) { console.log("getting game plays store"); return this.store.find('gameplay', {ownedgame: params.owned_game_id}); } });
and how i've modeled fixture data:
ownedgame.reopenclass({ fixtures: [ { id: "1", rating: "8.25", game: "1", plays: [1,2]}, { id: "2", rating: "8.25", game: "2", plays: []}, { id: "3", rating: "8.25", game: "3", plays: []}, { id: "4", rating: "8.25", game: "4", plays: []} ] }); gameplay.reopenclass({ fixtures: [ {id: "1", date: "2015-01-01", ownedgame: "1"}, {id: "2", date: "2015-02-01", ownedgame: "1"} ] });
if ownedgame route setting model, can grab model reference via modelfor() , pluck off id. abstract away actual param name parent route well.
ember has no docs on what's private , public on transition instance, fact pass in params , transition model hook suggests me it's not 100% safe grab params out of transition object unless you're cool non-deprecation-notice-breaking-changes months down road.
also, this.resource() being deprecated in 1.13; if new project i'd opt this.route() way.
Comments
Post a Comment