title: How to associate model to another model by two foreignKeys ? (in sequelize)
body: <p>Let's imagine situation</p>
  
  <p>You have two models:
  <strong>event_user</strong> with attributes: <em>id</em>
  <strong>event_user_message</strong> with attributes: <em>user_from_id, user_to_id</em></p>
  
  <p><strong>You want to get <em>20</em> event_users that were in contact (by message/s) with user X</strong></p>
  
  <p><strong>definition of associations</strong></p>
  
  <pre><code>EventUser.hasMany(eventUserMessages, as: "from", foreignKey: "user_from_id")
  EventUser.hasMany(eventUserMessages, as: "to", foreignKey: "user_to_id")
  
  EventUserMessages.belongsTo(eventUser, as: "from", foreignKey: "user_from_id")
  EventUserMessages.belongsTo(eventUser, as: "to", foreignKey: "user_to_id")
  </code></pre>
  
  <p><strong>Solution 1</strong>
  <em>problem</em>: <em>in this case I get only users that had two ways conversation</em></p>
  
  <p>var include, limit, where;
  limit = parameters.limit ? parameters.limit : 20;</p>
  
  <pre><code>include.push({
    model: models.eventUserMessages,
    as: "to",
    where: {user_from_id: parameters.inConnectionWith}
    attributes: []
  });
  
  include.push({
    model: models.eventUserMessages,
    as: "from",
    where: {user_to_id: parameters.inConnectionWith}
    attributes: []
  });
  
  eventUserModel.findAll({
    include: include,
    where: where
  })
  </code></pre>
  
  <p><strong>Solution 2</strong>
  In this solution you get all expected result
  <em>problem</em>: <em>in this solutions is you can not use Limit (does not work)</em></p>
  
  <pre><code>include.push({
    model: models.eventUserMessages,
    as: "to",
    required: false,
    attributes: []
  });
  
  include.push({
    model: models.eventUserMessages,
    as: "from",
    required: false,
    attributes: []
  });
  
  where = Sequelize.and(where, Sequelize.or({
    "to.user_from_id": parameters.inConnectionWith
  }, {
    "from.user_to_id": parameters.inConnectionWith
  }));
  
  eventUserModel.findAll({
    include: include,
    where: where
  })
  </code></pre>
  
  <p>will appreciate if you provide some suggestions about how to achieve this</p>
  
  <p>thanks in Advance</p>