2017-05-22 5 views
1

セージは、Studentテーブルにありますが、私は2017-Sageを使用して、生徒の誕生の年を照会したいが、私はそれを行う方法がわからない、私はこのように行うことを試みた:Sequelizeを使って仮想列をクエリする方法は?

db.Student.findAll({ 
     attributes: ['Sname','Ssex',[2017-Sequelize.col('Sage'),'Year of birth']], 
     where: { 
      Clno: { 
       $in: ['01311','10665'] 
      } 
     } 
    }) 

それはエラーが来る:

UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: attr[0].indexOf is not a function 
+0

悲しい話、私を助けて誰もありません。 – laoqiren

答えて

0

Sequelize.VIRTUALのデータ型をチェックするとよいでしょう。

だから、このようなものは、学生モデルの定義に必要になる可能性があります:

Student = sequelize.define('student', { 
    ... 
    birthYear: { 
     type: Sequelize.VIRTUAL(Sequelize.INTEGER, "(2017 - `students`.age) as birthYear") 
    } 
} 

より多くの例はここに用意されていますhttps://github.com/sequelize/sequelize/issues/7350

関連する問題