title: Access model instance methods in view (Sails.js / EJS)
body: <p>I've noticed that when a model instance (object) is passed to a view it is stripped of all functions. Is there any way around this?</p>
  
  <p>Example:</p>
  
  <p>My User model has method fullName which intelligently merges first name, last name, and prefix.</p>
  
  <p>In the controller I have:</p>
  
  <pre><code>User.find().done(function(err,users){
    res.view({
      users:users
    });
  });
  </code></pre>
  
  <p>If I loop through users in the controller I can do user.fullName();</p>
  
  <p>If I do the same in the view I get an undefined method error.</p>
  
  <p>I can access the model attributes directly in either the controller or view (eg user.firstName, user.lastName)</p>
  
  <p>On other MVC architectures (eg. rails / zendPHP) I usually do things like this in the model and can call user.fullName() wherever I need it in the view which allows me to keep DRY and consistent throughout the system.</p>
  
  <p>Why doesn't this work and is there a way to make it work?</p>
  
  <p><strong>Model</strong></p>
  
  <pre><code>module.exports = {
      attributes: {
          email: {
            type: 'string',
            required: true,
            unique: true,
            email: true
          },
          password: {
            type: 'string',
            required: true
          },
          firstName: {
            type: 'string',
            required: false,
            maxLength: 50,
            minLength: 2
          },
          lastName: {
            type: 'string',
            required: false,
            maxLength: 50,
            minLength: 2
          },
  
          // Returns full name of user (or just first / last if that's all we have)
          getFullName: function(){
            return _.str.trim((this.firstName || '') + ' ' + (this.lastName || ''));
          }
      }
  }
  </code></pre>
  
  <p><strong>View</strong></p>
  
  <pre><code>&lt;% users.forEach(function(user){ %&gt;
  &lt;tr&gt;
    &lt;td&gt;&lt;%= user.id %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= user.email %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= user.getFullName() %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= user.status %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= user.createdAt %&gt;&lt;/td&gt;
    &lt;td&gt;
      &lt;a href="#&lt;%= user.id %&gt;" class="btn btn-xs icon-edit"&gt;&lt;/a&gt;
      &lt;a href="#&lt;%= user.id %&gt;" class="btn btn-xs icon-trash"&gt;&lt;/a&gt;
    &lt;/td&gt;
  &lt;/tr&gt;
  &lt;% }); %&gt;
  </code></pre>
  
  <p>I've also tried console.log(user) in the loop and console.log(users) before the loop in both the controller and the view and it's obvious methods are stripped when the model is passed to the view. I've also tried the build in method user.toJSON() and I get an undefined method error in the view, but it works as expected in the controller.</p>