I am using ember-data#canary and it has a serious bug when finding record from the store.
File: router.js
this.resource('games', function() {
this.route('game', { path: '/:game' });
});
File: games_route.js
App.GamesRoute = Ember.Route.extend({
model: function() {
// request: GET /api/games
// response: { games: [
// { id: 1, slug: lym, name: lose your marbles }
// ] }
return this.store.find('game');
}
});
File: game_route.js
App.GamesGameRoute = Ember.Route.extend({
model: function(params) {
// this query causes bogus data to show up.
// request: GET /api/games/lym
// response: { game: { id: 1, slug: lym, name: lose your marbles } }
return this.store.find('game', params.game);
},
serialize: function(game) {
return { game: game.get('slug') };
}
});
File game_model.js
App.Game = DS.Model.extend({
slug: DS.attr('string'),
name: DS.attr('string'),
});
When I visit /games
ember-inspector data tab shows 1 game loaded.
`id` `slug` `name`
1 lym lose your marbles
When I visit /games/lym
ember-inspector data tab shows 2 game loaded.
`id` `slug` `name`
1 lym lose your marbles
lym undefined undefined
the second data is clearly bogus. I don't know where it comes from and it is causing me trouble.
when you call this.store.find('game', params.game)
ember data thinks that lym
is an id and creates empty record with this id
. Then it receives payload with actual record and stores with id=1.
Basically, in store.find
you should use actual id, not a slug, even if your API supports slugs.