2015-01-21 13 views
0

我試圖擺脫在更新前鉤sequelize模型中的所有字段及其對應的值,但我想不出我的錯誤sequelizejs beforeValidate得到鍵和值轉換成目標

,{ 
    timestamps: false, 
    underscored: true, 
    hooks: { 
     beforeValidate: function(transaction, options, fn) { 
     var ObjectToHash = transaction.getDataValue(); // Here I'm trying to get only the fields and their values 
     makehash(ObjectToHash) 
     .then(function(res){ 
      transaction.hash = res; 
      fn(null, transaction) 
     }) 

     } 
    } 
    } 

是getDataValue()正確的功能呢?

回答

0

愚蠢應懲罰;)

beforeValidate: function(transaction, options, fn) { 
     console.log('beforeCreate hook') 
     var ObjectToHash = transaction.get(); 
     console.log(ObjectToHash) 
     makehash(ObjectToHash) 
     .then(function(res){ 
      console.log('hash created for: '+transaction.id) 
      transaction.hash = res; 
      fn(null, transaction) 
     }) 

     }