0
votes

I have this model:

App.Game = DS.Model.extend({
    name: attr(),
    uri: attr()
});

and this route:

App.GamesRoute = Ember.Route.extend({
  model: function() {
      return this.store.find('game');    
  }
});

This works fine, calls the backend server, and stores elements in the store (I've checked with Ember inspector). This is the json I return:

{"games":[{"id":"TicTacToe","name":"TicTacToe","uri":"http://localhost:10000/games/TicTacToe"}]}

Now I have this template for 'games' (snipped):

{{#each game in model}}
{{#link-to 'games.matchlist' game.id}}{{game.uri}}{{/link-to}}

This shows the URI for each game. Now in the games.matchlist route what I would like to do is to search in the store by the game_id received param and get the game URI. The reason is that the server doesn't follow RESTAdapter conventions, and I would like to make a custom AJAX query to that URI myself. This doesn't work:

App.GamesMatchlistRoute = Ember.Route.extend({model: function(params) {
   var store = this.store;
   var game = store.find('game', params.game_id)
   console.log(game);
   console.log("URI: " + game.uri);

at this point, game is an object but it's not an instance of my model. It doesn't have a uri attribute. What am I doing wrong? I'm feeling that I'm missing something obvious.

2

2 Answers

0
votes

I'm on my mobile, but you need to create a GameAdapter and customize I believe the fetch function. Checkout the docs for adapters on the ember site and you should have your answer.

Your other option is to fetch the data from your server and use this.store.pushPayload(data).

Docs here: http://emberjs.com/api/data/classes/DS.Store.html#method_pushPayload

And the adapter docs here: http://emberjs.com/guides/models/customizing-adapters/

0
votes

If you want to get records without hitting the server and you know you already have it in the store, use this.store.getById('game', ID).