title: Handlebars Nested Each Statement
body: <p>I am attempting nest an each statement to handle the two objects that are available within my view. There is a relationship between the two objects with the <code>userId</code> on the <code>card</code> as the connection to the <code>userId</code> on the <code>user</code> table, which might be how this could work. I figure that I might have to end up registering a helper to have this work, but I'm not sure where to start. I attempted to bypass this process with the following handlebars syntax, but I get <code>TypeError: inverse is not a function</code>:</p>
  
  <pre><code>{{#each this.fullNameSlug ../user.fullNameSlug}}
              &lt;h5&gt;{{this.fullNameSlug}}&lt;/h5&gt;
  {{/each}}
  </code></pre>
  
  <p>Here is the full view:</p>
  
  <pre><code>{{#each card}}
  &lt;div class="row"&gt;
      &lt;div class="card col-md-6 col-md-offset-3"&gt;
          &lt;div class="card-date"&gt;
              &lt;p class="card-date"&gt;{{this.cardDateSlug}}&lt;/p&gt;
          &lt;/div&gt;
          &lt;div class="card-header"&gt;
              &lt;h3 class="card-title"&gt;{{this.title}}&lt;/h3&gt;
              {{#each this.fullNameSlug ../user.fullNameSlug}}
              &lt;h5&gt;{{this.fullNameSlug}}&lt;/h5&gt;
              {{/each}}
          &lt;/div&gt;
          &lt;div class="card-body"&gt;
  {{/each}}
  </code></pre>
  
  <p>Here is the route with the two objects (card, user) that are accessible in the view:</p>
  
  <pre><code>/*====   /  ====*/
  
  appRoutes.route('/') 
  
      .get(function(req, res){
          models.Card.findAll({
              order: 'annotationDate DESC',
              include: [{
                  model: models.User,
                  where: { organizationId: req.user.organizationId },
                  attributes: ['organizationId', 'userId', 'fullNameSlug']
              }],
              limit: limitAmount.limit
          }).then(function(annotation){
              res.render('pages/app/activity-feed.hbs',{
                  card: card,
                  user: req.user
              });
          });
      })
  </code></pre>
  
  <p><strong>Card object:</strong></p>
  
  <pre><code>module.exports = function(sequelize, DataTypes) {
  
  var path = require('path');
  var moment = require('moment');
  
  var Card = sequelize.define('card', {
      cardId: {
          type: DataTypes.INTEGER,
          field: 'card_id',
          autoIncrement: true,
          primaryKey: true
      },
      cardDate: {
          type: DataTypes.DATE,
          field: 'card_date',
          isDate: true
      },
      reportLink: {
          type: DataTypes.TEXT,
          field: 'report_link'
      },
      fileAttachment: {
          type: DataTypes.STRING,
          field: 'file_attachment'
      },
      userId: {
          type: DataTypes.INTEGER,
          field: 'user_id'
      },
      discoverySourceId: {
          type: DataTypes.INTEGER,
          field: 'discovery_source_id'
      }
  },
  
   {
      freezeTableName: true,
      getterMethods: {
          cardDateSlug: function(){
              var date = new Date(this.getDataValue('annotationDate'));
              var momentDate = moment(date).utc().format("MM/DD/YYYY"); 
  
              return momentDate;
  
          }
      },
      classMethods: {
          associate: function(db) {
              Card.belongsTo(db.User, {foreignKey: 'user_id'}),
          }
      }
  });
      return Card;
  }
  </code></pre>
  
  <p><strong>User object:</strong></p>
  
  <pre><code>var bcrypt   = require('bcrypt-nodejs');
  
  module.exports = function(sequelize, DataTypes) {
  
  var User = sequelize.define('user', {
      userId: {
          type: DataTypes.INTEGER,
          field:'user_id',
          autoIncrement: true,
          primaryKey: true
      },
      firstName: {
          type: DataTypes.STRING,
          field: 'first_name'
      },
      lastName: {
          type: DataTypes.STRING,
          field: 'last_name'
      },
      email: {
          type: DataTypes.STRING,
          isEmail: true,
          unique: true,
          set: function(val) {
              this.setDataValue('email', val.toLowerCase());
          }
      },
      password: DataTypes.STRING,
      organizationId: {
          type: DataTypes.INTEGER,
          field: 'organization_id',
          allowNull: true
      },
      authenticationToken: {
          type: DataTypes.STRING,
          field: 'authentication_token'
      },
      resetPasswordToken: {
          type: DataTypes.STRING,
          field: 'reset_password_token'
      },
      resetPasswordExpires: {
          type: DataTypes.DATE,
          field: 'reset_password_expires'
      }
  }, {
      freezeTableName: true,
      getterMethods: {
          fullNameSlug: function(){
              var fullName = this.getDataValue('firstName') + ' ' + this.getDataValue('lastName');
              return fullName;
          }
      },
      classMethods: {
          associate: function(db) {
              User.belongsToMany(db.Organization, { through: 'member', foreignKey: 'user_id'})
          },
          generateHash: function(password) {
              return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null);
          },
      },
      instanceMethods: {
          validPassword: function(password) {
              return bcrypt.compareSync(password, this.password);
          },
      },  
  });
      return User;
  }
  </code></pre>