title: Problem constructing query with sequelize
body: <p>I am having problems recreating the following query in Sequelize. I have been sitting for hours trying to figure this out. </p>
  
  <p>I am using camelCase instead of snake_case so I cannot reuse the same query. </p>
  
  <p>The query does not work if I exchange all snake_cased variables to camelCase in the query. I get back "relation \"directmessages\" does not exist". I cannot access the directmessages table in psql with TABLE directmessages; - but I know its supposed to be there.</p>
  
  <p>I can also not figure out how to do the same query with sequelize.</p>
  
  <p>Basically I need to fetch every User the current user has already direct messaged with. Either as a sender or receiver. </p>
  
  <pre><code>  models.sequelize.query(
      'select distinct on (u.id) u.id, u.username from users as u join direct_messages as dm on (u.id = dm.sender_id) or (u.id = dm.receiver_id) where (:currentUserId = dm.sender_id or :currentUserId = dm.receiver_id) and dm.team_id = :teamId',
      {
        replacements: { currentUserId: user.id, teamId: id },
        model: models.User,
        raw: true,
      },
  </code></pre>
  
  <p>These are the relevant models for this query:</p>
  
  <p>User Model:</p>
  
  <pre><code>User.associate = (models) =&gt; {
      User.belongsToMany(models.Team, {
          through: models.Member,
          foreignKey: 'userId',
      })
      User.belongsToMany(models.Channel, {
          through: 'channel_member',
          foreignKey: 'userId',
      })
  
  }
  </code></pre>
  
  <p>DirectMessage Model:</p>
  
  <pre><code>DirectMessage.associate = (models) =&gt; {
      DirectMessage.belongsTo(models.Team, {
          foreignKey: 'teamId',
      })
      DirectMessage.belongsTo(models.User, {
          foreignKey: 'receiverId',
      })
      DirectMessage.belongsTo(models.User, {
          foreignKey: 'senderId',
      })
  }
  </code></pre>
  
  <p>I tried creating the query with sequelize like this:</p>
  
  <pre><code>models.User.findAll({ 
              include:[{
                  model: models.DirectMessage,
                  where: {                        
                      teamId, 
                      [models.sequelize.Op.or]: [{senderId: user.id}, {receiverId: user.id}]
                  }
              }]
              }, { raw: true })
  </code></pre>
  
  <p>I get back "message": "directMessage is not associated to user!", which I presume is because DirectMessage is associated to User, but not the other way around.</p>
  
  <p>Does anybody have any tips of how I can reconstruct this query?</p>