-
Notifications
You must be signed in to change notification settings - Fork 76
Closed
Labels
Description
Can somebody show an example of creating relations between the models?
I want to relate a model Tutorial and Comment. How can i do that?
I make it so:
'use strict'
const Sequelize = require('sequelize')
module.exports = function (sequelize) {
const comment = sequelize.define('comment', {
content: {
required: true,
type: Sequelize.TEXT,
allowNull: false
},
tutorialId: {
required: true,
type: Sequelize.INTEGER
}
}, {
timestamps: true,
freezeTableName: true
})
comment.belongsTo(sequelize.models.tutorial)
comment.sync({
force: true
})
return comment
}But sometimes, when i start my application i have error:
Unhandled rejection SequelizeDatabaseError: relation "tutorial" does not existI used to work only with mongoDB. But I think I need to learn sequelize.
It would be great if we had more examples that show how to work with the database, how to set up the relationship between models and between services. I read the documentation, but it very much and I'm not like I can not configure it to work properly.
reduardo7, Ziggoto, valeriu-dev, jermsam and saschwarz