title: sencha touch 2: binding associations data to existing store
body: <p>I have a simple data model that looks something like this (actual code below):</p>
  
  <pre><code>model Game:
    fields: id, team_1_id, team_2_id
  
  model GameScore:
    fields: id, game_id, team_1_score, team_2_score, is_final, submission_date
  
  model SpiritScore:
    fields: id, game_id, team_1_score, team_2_score
  </code></pre>
  
  <p>What I want seems simple.  I already have code that loads Games and GameScores in bulk.  I have a 'Game' instance in hand, and can call gameScores().  And I get a store, but it's empty.  I have code that will dynamically load it, by placing the store into the model's hasMany definition.  But what I would really like is some way to bind the Game.gameScores() call to the my existing GameScores store.  Even if it used a normal filter underneath, that gives me a single record that I can bind and use in a view.  (Important note: the data does not come in nested form.)</p>
  
  <p>This leads to my second question.  Game:GameScores is 1:many, but I only ever display the most recent one (from live score reporting).  What is the general approach here?  I can also manually build a filter from the game_id, but I can only bind 1 record to a view, so I don't see how I can bring that other information into a view, short of a proper hasMany relationship.  Is there another way?</p>
  
  <p>Any and all advice, including telling me to RTFM (with a link to the relevant manual) would be greatly appreciated!  I've been pulling my hair out on this (pro bono side project) for the last week.</p>
  
  <p>Cheers!</p>
  
  <p>b</p>
  
  <pre><code>Ext.define('TouchMill.model.Game', {
      extend: 'Ext.data.Model',
  
      config: {
          fields: [ 'id', 'team_1_id', 'team_2_id' ],
          hasMany: {
              model: 'TouchMill.model.GameScore',
              name: 'gameScores',
          },
      },
  });
  
  Ext.define('TouchMill.model.GameScore', {
      extend: 'Ext.data.Model',
  
      config: {
          fields: [ 'id', 'game_id', 'team_1_score', 'team_2_score', 'is_final', 'submission_date', ],
      },
      // belongsTo necessary?  Don't think so unless I want parent func?
  });
  
  Ext.define('TouchMill.model.SpiritScore', {
      extend: 'Ext.data.Model',
  
      config: {
          fields: [ 'id', 'game_id', 'team_1_score', 'team_2_score', ],
      },
  },
  </code></pre>