javascript - Sequelize with postgresql saving array - Stack Overflow

I am using sequelize in my application. I have postgres as underlying database.But when I tried to sav

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);
  });

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);
  });
Share Improve this question edited Aug 30, 2014 at 11:47 user123 asked Aug 30, 2014 at 11:34 user123user123 53812 silver badges25 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

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() {});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744692331a4588282.html

相关推荐

  • javascript - Sequelize with postgresql saving array - Stack Overflow

    I am using sequelize in my application. I have postgres as underlying database.But when I tried to sav

    23小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信