2017-03-27 2 views
0

私はdocumentation for Sequelizeを読んだが、defineを使う方法は分かっているが、Sequelize定義からtype/allowNull/primaryKey/autoIncrementプロパティをどのように読むことができないのか分からない。これはsequelize-autoによって生成されたファイルの一部です。Sequelizeで表の列プロパティを読み取るにはどうすればよいですか?

/* jshint indent: 2 */ 

module.exports = function(sequelize, DataTypes) { 
    return sequelize.define('account', { 
    id: { 
     type: DataTypes.BIGINT, 
     allowNull: false, 
     primaryKey: true, 
     autoIncrement: true 
    }, 
    parent_account_id: { 
     type: DataTypes.BIGINT, 
     allowNull: false, 
     references: { 
     model: 'account', 
     key: 'id' 
     } 
    }, 
    master_account_id: { 
     type: DataTypes.BIGINT, 
     allowNull: false, 
     references: { 
     model: 'account', 
     key: 'id' 
     } 
    }, 
    name: { 
     type: DataTypes.STRING, 
     allowNull: false 
    }, 
    // ... 

答えて

0

モデルとmodelManagerの構造に着目:

models: { user: user }, 
modelManager: ModelManager { models: [ user ], sequelize: [Circular] }, 
私は、オブジェクトが大きすぎるなければならないので、それはユーザーを拡大していなかったので、私が試したことを考え出し

var userDefinition = this.orm["modelManager"].getModel("user"); 
if (userDefinition.attributes.id.type.key == "BIGINT") ... 

modelManagerはコンパイル時に初期化されないため、TypeScriptでは[]を使用する必要があります。

関連する問題