Add example for model relations
See original GitHub issueCan 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 exist
I 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.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:5
- Comments:24 (10 by maintainers)
Top Results From Across the Web
Creating model relations | LoopBack Documentation
The easiest way to create a new relation between existing models is to use the slc loopback:relation , or the apic loopback:relation ,...
Read more >Adding cross-model relations - Bizzdesign Support
Cross-model relations can be added between objects, but also between objects and diagrams or views, and between diagrams and/or views. A single ...
Read more >Relationships between tables in a Data Model
A relationship is a connection between two tables of data, based on one column in each. A workbook can store each piece of...
Read more >Models with Relationships in FastAPI - SQLModel
We cannot simply include all the data, including all the internal relationships, because each hero has an attribute team with their team, and...
Read more >Eloquent: Relationships - The PHP Framework For Web Artisans
It is possible to construct more advanced "has one of many" relationships. For example, a Product model may have many associated Price models...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
My current approach:
It seems I figured.