2014-08-30 24 views
1

我在我的應用程序中使用了sequelize。我有postgres作爲底層數據庫。 但是,當我試圖挽救我得到了以下錯誤實例使用postgresql保存數組進行續集

[錯誤:缺少維度值]

我有以下型號

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

我發送HTTP POST請求爲

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

我是這樣保存對象

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

回答

0

我試着發送你的模型對象,如你所述,並且得到錯誤SequelizeValidationError: "['JAVA','REST','API']" is not a valid array。也許你在舊版本的Sequelize上遇到了不同的錯誤。然後,我確定tags值是一個JavaScript數組而不是字符串,它的工作。

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