title: How to trigger a model update from another model in a collection in Backbone.js?
body: <h3>Update: Here is a working demo of the project I was working on: <a href="http://www.newedenfaces.com" rel="nofollow">http://www.newedenfaces.com</a></h3>
  
  <p>I have two views: <strong>PeopleView</strong> that holds 2 thumbnails (collection) and <strong>PersonView</strong> - each thumbnail itself (model).</p>
  
  <p>This is basically a Facemash clone where you have two images side-by-side. If one person wins the game, another one loses the game.</p>
  
  <p>In order to update <em>wins count</em>, it's easy, just add this to the <strong>PersonView</strong>:</p>
  
  <pre><code>// Model View
  events: {
      'click img': 'winner'
  },
  winner: function() {
      this.model.set('wins', this.model.get('wins') + 1);
      this.model.save();
  }
  </code></pre>
  
  <p>But how do I update the other model by incrementing the <em>losses count?</em> Or should I be doing this type of logic at the collection level rather than on an individual model?</p>
  
  <h1>Update</h1>
  
  <p>Until I find an elegant solution I've managed to solve this problem using this hack:</p>
  
  <pre><code>// Collection View
  initialize: function() {
      this.collection.on('change:wins', this.updateLosses, this);
    },
  
    updateLosses: function(model) {
      var winnerIndex = this.collection.indexOf(model);
      var otherModel = this.collection.at(Math.abs(1 - winnerIndex));
      otherModel.set('losses', otherModel.get('losses') + 1);
      otherModel.save();
      this.render();
    },
  </code></pre>
  
  <p>My <strong>PersonView</strong> still handles the update of wins count. However the <strong>PeopleView</strong> collection view listens for the event when wins count is updated. When that happens it takes that model and gets its index position. Since I only have 2 views / 2 models, the other model must have been a "loser". You get the index of the other model via <code>Math.abs(1 - winnerIndex)</code>, and the only things that you have to do is update its <em>losses count</em>.</p>
  
  <p><em><strong>Note</em></strong>: I have just started learning Backbone, so this is my first project using it. <strong>I really hope there is a better way to do this.</strong> If you know, post an answer so I could accept and close this question.</p>