title: Sails.js populate nested associations
body: <p>I've got myself a question regarding associations in Sails.js version 0.10-rc5. I've been building an app in which multiple models are associated to one another, and I've arrived at a point where I need to get to nest associations somehow.</p>
  
  <p>There's three parts:</p>
  
  <p>First there's something like a blog post, that's being written by a user. In the blog post I want to show the associated user's information like their username. Now, everything works fine here. Until the next step: I'm trying to show comments which are associated with the post.</p>
  
  <p>The comments are a separate Model, called Comment. Each of which also has an author (user) associated with it. I can easily show a list of the Comments, although when I want to display the User's information associated with the comment, I can't figure out how to populate the Comment with the user's information.</p>
  
  <p>In my controller i'm trying to do something like this:</p>
  
  <pre><code>Post
    .findOne(req.param('id'))
    .populate('user')
    .populate('comments') // I want to populate this comment with .populate('user') or something
    .exec(function(err, post) {
      // Handle errors &amp; render view etc.
    });
  </code></pre>
  
  <p>In my Post's 'show' action i'm trying to retrieve the information like this (simplified):</p>
  
  <pre><code>&lt;ul&gt; 
    &lt;%- _.each(post.comments, function(comment) { %&gt;
      &lt;li&gt;
        &lt;%= comment.user.name %&gt;
        &lt;%= comment.description %&gt;
      &lt;/li&gt;
    &lt;% }); %&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>The comment.user.name will be undefined though. If I try to just access the 'user' property, like comment.user, it'll show it's ID. Which tells me it's not automatically populating the user's information to the comment when I associate the comment with another model. </p>
  
  <p>Anyone any ideals to solve this properly :)?</p>
  
  <p>Thanks in advance!</p>
  
  <p>P.S.</p>
  
  <p>For clarification, this is how i've basically set up the associations in different models:</p>
  
  <pre><code>// User.js
  posts: {
    collection: 'post'
  },   
  hours: {
    collection: 'hour'
  },
  comments: {
    collection: 'comment'
  }
  
  // Post.js
  user: {
    model: 'user'
  },
  comments: {
    collection: 'comment',
    via: 'post'
  }
  
  // Comment.js
  user: {
    model: 'user'
  },
  post: {
    model: 'post'
  }
  </code></pre>