title: How to use sequelize and PostGIS to query by distance?
body: <p>I have an address model (Sequelize) declared the following way:</p>
  
  <pre><code>var address = sequelize.define("address", {
      id: {
          type: DataTypes.INTEGER,
          autoIncrement: true,
          primaryKey: true
      },
      coordinates: {
          type: DataTypes.GEOMETRY,
          allowNull: false
      },
      /* ... */
  });
  </code></pre>
  
  <p>And now I'm trying to retrieve all addresses in distance 25Km radius:</p>
  
  <pre><code>const distance = models.sequelize.fn('ST_Distance', models.sequelize.col('coordinates'), city.coordinates);
  
  return models.address.findAll({
      where: models.sequelize.where(distance, { $lte: 25000 })
  });
  </code></pre>
  
  <p>That translates into the following query:</p>
  
  <pre><code>SELECT * FROM "addresses" AS "address" WHERE 
  ST_Distance("coordinates", "type" = \'Point\' AND "coordinates" IN (41.544031, -8.426646))
  &lt;= \'25000\';
  </code></pre>
  
  <p>That throws the error: column "type" does not exist.</p>
  
  <p>sequelize: 3.23.3,
  postgres: 9.4.12</p>
  
  <p>What am I doing wrong?</p>