title: How to implement search feature using SequelizeJS?
body: <p>I have a Ticket model and a Comment model. The Ticket has a hasMany relationship to Comment model. I want to search tickets by a keyword. The keyword will be matched againts the subject attribute of the ticket model and the body attribute of the comment model.</p>
  
  <p>The code below doesn't work:</p>
  
  <pre><code>var options = {
    where: {
      $or: [
        {
          subject: {
            like: '%' + query + '%'
          },
        },
        {
          'Comment.body': {
            like: '%' + query + '%'
          },
        }
      ]
    },
    include: [
      { model: Comment },
    ]
  };
  
  Ticket.findAll(options);
  </code></pre>
  
  <p>This is the error: "Possibly unhandled SequelizeDatabaseError: column Ticket.Comment.body does not exist"</p>
  
  <p>I also tried the code below but it also doesn't work:</p>
  
  <pre><code>var options = {
    where: {
      CompanyId: req.company.id,
      $or: [
        {
          subject: {
            like: '%' + query + '%'
          },
        },
        sequelize.cast(sequelize.col('comment.body'), 'TEXT', 'LIKE', '%' + query + '%')
      ]
    },
    include: [
      { model: Comment, as: 'comment', where: {} },
    ]
  };
  
  Ticket.findAll(options);
  </code></pre>
  
  <p>The error is: "Possibly unhandled Error: Comment (comment) is not associated to Ticket!"</p>
  
  <p>And this one:</p>
  
  <pre><code>var options = {
    where: {
      CompanyId: req.company.id,
      $or: [
        {
          subject: {
            like: '%' + query + '%'
          },
        },
        sequelize.where(sequelize.col('Comments.body'), 'LIKE', '%' + query + '%')
      ]
    },
    include: [
      { model: Comment},
    ]
  };
  
  Ticket.findAll(options);
  </code></pre>
  
  <p>Error: "Possibly unhandled SequelizeDatabaseError: missing FROM-clause entry for table "Comments"" </p>
  
  <p>I'm using SequelizeJS version 2.0.4</p>
  
  <p>I saw these related issues on the Sequelizejs repository on Github: </p>
  
  <ul>
  <li><a href="https://github.com/sequelize/sequelize/issues/3261" rel="noreferrer">https://github.com/sequelize/sequelize/issues/3261</a></li>
  <li><a href="https://github.com/sequelize/sequelize/issues/3095" rel="noreferrer">https://github.com/sequelize/sequelize/issues/3095</a></li>
  <li><a href="https://github.com/sequelize/sequelize/issues/3527" rel="noreferrer">https://github.com/sequelize/sequelize/issues/3527</a></li>
  </ul>
  
  <p>Anyone knows a solution? Thanks in advance!</p>