title: How to define BackboneJS models and collections that have an additional paramenter in the URL?
body: <p>I have a model (and it's corresponding collection) that have an URL with an additional parameter. For instance, the URL for the posts <code>collection</code> would be something like:</p>
  
  <pre><code>/rest-api/posts/2/comments/
  </code></pre>
  
  <p>and for a particular comment the URL would be something like:</p>
  
  <pre><code>/rest-api/posts/2/comments/3/
  </code></pre>
  
  <p>What's the best pattern to define and instantiate the comments collection and models?</p>
  
  <p>I'm currently doing this:</p>
  
  <pre><code>var Comment = Backbone.Model.extend({
      url: function () {
          var base = '/rest-api/posts/' + this.get('post_id') + '/comments/';
          if (this.isNew()) { return base; }
          return base + this.id + '/';
      },
      // ...
  });
  
  var CommentsCollection = Backbone.Collection.extend({
      model: Comment,
      url: function () {
          return '/rest-api/posts/' + this.post_id + '/comments/';
      },
      initialize: function (options) {
           this.post_id = options.post_id;
      },
      // ...
  });
  </code></pre>
  
  <p>And instantiate the collection like this:</p>
  
  <pre><code>CommentsList = new CommentsCollection({ post_id: current_post_id });
  </code></pre>
  
  <p>Is this the <code>accepted</code> pattern for doing this in Backbone.js? I'm introducing myself to this  new framework, I just want to code this in a readable and maintainable way.</p>