title: Handling a belongs_to relation with backbone.js
body: <p>I am kind of new with backbone.js and i am struggling with fetching a collection with a belong_to relation.</p>
  
  <p>I would like to fetch a list of users (users/ GET) and i would like to display them all but with a belongs_to association.</p>
  
  <p>For example to display the company name of the user. Somebody knows a solution?</p>
  
  <p>I am using Ruby on Rails 3 with CouchDB</p>
  
  <h1>users controller</h1>
  
  <pre><code>def index
    User.all
  end
  </code></pre>
  
  <h1>Backbone collection</h1>
  
  <pre><code>class UserCollection extends Backbone.Collection
  
    url: -&gt;
      app.routes.users_url
  
    model: User
  </code></pre>
  
  <h1>Backbone model</h1>
  
  <pre><code>class User extends Backbone.Model
  
    idAttribute: '_id'
  
    defaults: {
      "email": null
      "mobile": null
      "loc": null
    }
  
    url: -&gt;
      app.routes.users_url + '/' + (@id || '')
  </code></pre>
  
  <p>I would like to show the company name like this...</p>
  
  <pre><code>%script{:id =&gt; "user-resource-template", :type =&gt; "text/template"}
    %td= check_box_tag "select", 1, false, :class =&gt; "checkbox", "data-id" =&gt; raw("&lt;%= _id %&gt;")
    %td &lt;%= name %&gt;
    %td &lt;%= email %&gt;
    %td &lt;%= company.name %&gt;
  </code></pre>