user123
user123

Reputation: 538

Sequelize with postgresql saving array

I am using sequelize in my application. I have postgres as underlying database. But when I tried to save instances I got following error

[error: missing dimension value]

I have the following model

module.exports = function(sequelize, DataTypes) {
  var Mymodel = sequelize.define('Mymodel', {
        id: {type : DataTypes.INTEGER, autoIncrement : true, primaryKey: true},
        title: {
          type: DataTypes.STRING(128),
          validate: {
            notNull: true,
            notEmpty: true
          }
        },
        tags: DataTypes.ARRAY(DataTypes.TEXT)
      });
  return Mymodel;
}

I am sending http post request as

{
"title":"Test challenge",
  "tags" : "['JAVA','REST','API']"
}

I am saving object like this

Mymodel.create(model).success(function(model) {
    callback(null, challenge);
  }).error(function(err) {
    callback(err, null);
  });

Upvotes: 5

Views: 7376

Answers (1)

Evan Siroky
Evan Siroky

Reputation: 9438

I tried sending over your model object as you stated and did get the error SequelizeValidationError: "['JAVA','REST','API']" is not a valid array. Perhaps you got a different error on an older version of Sequelize. Then, I made sure the tags value was a JavaScript array instead of a string and it worked.

Mymodel.create({ 
  title: 'Test challenge', 
  tags: ['JAVA','REST','API']
}).then(function() {});

Upvotes: 4

Related Questions