mariadb 等效于{ type:Schema.Types.ObjectId,ref:“myModel”}来自Sequelize中的mongoose,NodeJS

uoifb46i  于 8个月前  发布在  Go
关注(0)|答案(1)|浏览(41)

我需要在Sequelize的帮助下编写一个模型,但是我在那里找不到Schema.Types.ObjectId,ref:“myModel”的等价物。我如何才能实现这一点?我对这项技术和数据库都是新手。
我试图从另一个模型中获取用户ID,并在DB中创建示例时将其放入此模型。它将帮助我实现JWT令牌模型。

const User = require('../').user
const {Sequelize} = require('sequelize')

module.exports = function (sequelize) {
  const model = sequelize.define("TokenModel", {
    user : {
      type: //Id from another Model like in Mongoose
    }
    refreshToken: {
      type: Sequelize.STRING,
    },
  }, {
    timestamps: false
  })

  return model
}
nbewdwxp

nbewdwxp1#

好吧,我想明白了:

modelA = belongsTo(modelB);
modelA = hasOne(modelB);

解决了这个问题。对不起,我对SQL数据库的基础知识不太了解:)

相关问题