英文:
Equivalent of { type: Schema.Types.ObjectId, ref:"myModel" } from mongoose in Sequelize. NodeJS
问题
我需要使用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,类似于Mongoose中的方式
},
refreshToken: {
type: Sequelize.STRING,
},
}, {
timestamps: false
})
return model
}
英文:
I need to write a model with help of Sequelize, but I can't find an equivalent of Schema.Types.ObjectId, ref:"myModel" there. How I can implement this one? I'm new in this technology and in DataBases.
I'm trying to get an User Id from another model and put to this one when creating an instance in DB. It' ll help me to implement JWT token model.
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
}
答案1
得分: 0
我明白了:
modelA = 属于(modelB);
modelA = 拥有一个(modelB);
问题已解决。抱歉,我对SQL数据库基础知识了解不够。
英文:
Okey, I figured out:
modelA = belongsTo(modelB);
modelA = hasOne(modelB);
Solved this. Sorry for my bad knowledge of basics of SQL databases
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论