title: How to reference associated models in a one-to-many relationship with Sails 0.10.x
body: <p>I'm using <code>Sails.js</code> version 0.10.x, and am just starting to try out it's <code>associactions</code> stuff.</p>
  
  <p>In my scenario I have a User who has many Documents.</p>
  
  <p>so in <code>/api/models/User.js</code> I have:</p>
  
  <pre><code>module.exports = {
    // snipped out bcrypt stuff etc
    attributes: {
       email: {
        type: 'string',
        unique: true,
        index: true,
        required: true
      },
      documents: {
        collection: 'document',
        via: 'owner'
      },
    }
  };
  </code></pre>
  
  <p>and in <code>/api/models/Document.js</code> I have:</p>
  
  <pre><code>module.exports = {
    attributes: {
      name:      'string',
      owner: {
        model: 'user'
      }
    }
  };
  </code></pre>
  
  <p>In my <code>DocumentController</code> I have the following:</p>
  
  <pre><code>fileData = {
    name: file.name,
    owner: req.user
  }
  
  Document.create(fileData).exec(function(err, savedFile){
    if (err) {
      next(err);
    } else {
      results.push({
        id: savedFile.id,
        url: '/files/' + savedFile.name,
        document: savedFile
      });
      next();
    }
  });
  </code></pre>
  
  <p>Looking in my local <code>mongo</code> database via the command line I can see that the documents have the owner field set as follows <code>"owner" : ObjectId("xxxxxxxxxxxxxxxxxxxxxxxx")</code> which is as expected.</p>
  
  <p>However when I inspect the <code>req.user</code> object later in the DocumentController via <code>sails.log.debug("user has documemts", req.user.documents);</code> I see</p>
  
  <pre><code>debug: user has documents [ add: [Function: add], remove: [Function: remove] ]
  </code></pre>
  
  <p>And not an array of <code>Document</code> objects.</p>
  
  <p>In my resulting <code>slim</code> template</p>
  
  <pre><code>if req.user.documents.length &gt; 0
    ul
      for doc in req.user.documents
        li= doc.toString()
  else
    p No Documents!
  </code></pre>
  
  <p>I always get "No Documents!"</p>
  
  <p>I seem to be missing something obvious but I'm not sure what that is.</p>