Skip to content

Sequelize not returning range data properly #6896

Closed

Description

@FREEZX

What am i doing?

Trying to access int4range data in postgresql, model find returning no actual data, just empty arrays

Here's my model

var Activity = sequelize.define('activity', {
    id: {
      type: Sequelize.UUID,
      defaultValue: Sequelize.UUIDV4,
      primaryKey: true
    },
    type: {
      type: Sequelize.ENUM('user', 'default'),
      allowNull: false
    },
    approved: {
      type: Sequelize.BOOLEAN,
      defaultValue: false,
      allowNull: false
    },
    name: {
      type: Sequelize.STRING,
      allowNull: false,
      trim: true
    },
    description: {
      type: Sequelize.STRING,
      allowNull: false,
      trim: true
    },
    content: {
      type: Sequelize.TEXT,
      trim: true
    },
    ageRange: {
      type: Sequelize.RANGE(Sequelize.INTEGER)
    },
    userRange: {
      type: Sequelize.RANGE(Sequelize.INTEGER)
    },
    timeRange: {
      type: Sequelize.RANGE(Sequelize.INTEGER)
    }
  }
);

Activity.belongsTo(User, {as: 'creator'});

Here's the code that's trying to access it:

/**
 * List of Articles
 */
exports.list = function(req, res) {
  Activity.findAll()
  .then(function(activitys){
    console.log(activitys[0].dataValues.ageRange);
    return res.send(activitys);
  })
  .catch(function(err){
    return res.status(400).send(err);
  });
};

I have a single row in the db with the ageRange having this value: [8, 77)

What do i expect to happen?

I expect the find query to return the in the response of the query.

What is actually happening?

The output for the request is this:

[
  {
    "id": "2108125d-3bfb-4c8f-9f37-5fa0df793179",
    "type": "user",
    "approved": false,
    "name": "Party",
    "description": "Throw a party",
    "content": null,
    "ageRange": [
      [],
      []
    ],
    "userRange": null,
    "timeRange": null,
    "createdAt": "2016-11-19T13:20:50.451Z",
    "updatedAt": "2016-11-19T13:20:50.472Z",
    "creatorId": "a0abee24-698e-4218-a5f2-d63d6ab69e28"
  }
]

and the console.log is outputting this:

[ [], [], inclusive: [ true, false ] ]

Dialect: postgres
Database version: PostgreSQL 9.5.5 running on ubuntu
Sequelize version: [email protected]

Activity

  1. FREEZX commented on Nov 19, 2016

    @FREEZX
    Author
  2. janmeier commented on Nov 23, 2016

    @janmeier
    Member

    Good work, thanks for taking the timing to scratch your own itch ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions