用不是Sequelize.Model的子类的东西进行调用

时间:2019-05-04 22:09:54

标签: mysql node.js typescript foreign-keys sequelize.js

当我想从Tweet对象向User对象创建外键时,出现此错误。我的意思是,一条推文中有一个User,而一个用户有一堆中。我正在使用TypeScript + NodeJS + express

  

tweets.belongs要使用不是Sequelize.Model的子类的东西进行调用

这是我的2个续集定义:

import database = require('../config/database')
import DBUser = require('./DBUser');
const Sequelize = require('sequelize')

const DBTweet = database.define('tweets', {
    tweetAuthorID: {
        type: Sequelize.INTEGER,
        allowNull: false,
    },
    timestamp: {
        type: Sequelize.STRING,
        allowNull: false,
    },
    content: {
        type: Sequelize.STRING,
        allowNull: false
    },
    postedImageURL: {
        type: Sequelize.STRING(255),
        allowNull: true,
        defaultValue: null,
    }
}, {
    timestamps: false
})

DBTweet.belongsTo(DBUser)

export = DBTweet

第二:

import database = require('../config/database')
import DBTweet = require('./DBTweet');
const Sequelize = require('sequelize')

const DBUser = database.define('users', {
    name: {
        type: Sequelize.STRING,
        allowNull: false
    },
    username: {
        type: Sequelize.STRING,
        allowNull: false,
        unique: true
    },
    loginType: {
        type: Sequelize.STRING,
        allowNull: false
    },
    email: {
        type: Sequelize.STRING,
        allowNull: true,
        defaultValue: null,
        unique: true
    },
    password: {
        type: Sequelize.STRING(255),
        allowNull: true,
        defaultValue: null
    },
    telephoneNumber: {
        type: Sequelize.STRING,
        allowNull: true,
        defaultValue: null,
        unique: true
    },
    profileImageID: {
        type: Sequelize.STRING,
        allowNull: false
    },
    bannerImageID: {
        type: Sequelize.STRING,
        allowNull: false
    },
    profileDescription: {
        type: Sequelize.STRING,
        allowNull: false
    }
}, {
    timestamps: false
})

DBUser.hasMany(DBTweet)

export = DBUser

0 个答案:

没有答案