最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Sequelize with postgresql saving array - Stack Overflow

programmeradmin0浏览0评论

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() {});
发布评论

评论列表(0)

  1. 暂无评论