Multiple relationships in express, between diferent models that are in different files #16747
Unanswered
juancruzsosagab
asked this question in
Help & Questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
hello! im trying to use sequelize in an express proyect. The thing is that i have 3 models that are related. Its like i have a parent, then a child and that child is related with other one. The things is that in the top level im experiencing an issue.
the error:
/home/training/mi-aplicacion-express/node_modules/sequelize/lib/associations/mixin.js:13
throw new Error(
${this.name}.hasMany called with something that's not a subclass of Sequelize.Model
);^
Error: TVShow.hasMany called with something that's not a subclass of Sequelize.Model
The models are like this:
/////////////////
const { DataTypes } = require('sequelize');
const sequelize = require('../sequelize');
const Season = require('./season');
const TVShow = sequelize.define('TVShow', {
title: {
type: DataTypes.STRING,
},
genre: {
type: DataTypes.STRING,
},
});
TVShow.hasMany(Season, { foreignKey: 'tvShowId' });
Season.belongsTo(TVShow, { foreignKey: 'tvShowId' });
TVShow.sync()
module.exports = TVShow;
/////////
const { DataTypes } = require('sequelize');
const sequelize = require('../sequelize');
const TVShow = require('./tvShow');
const Episode = require('./episode');
const Season = sequelize.define('Season', {
number: {
type: DataTypes.INTEGER,
},
})
Season.hasMany(Episode, { foreignKey: 'seasonId' });
Episode.belongsTo(Season, { foreignKey: 'seasonId' });
Season.sync()
module.exports = Season;
///////
const { DataTypes } = require('sequelize');
const sequelize = require('../sequelize');
const { associate } = require('./director');
const Season = require('./season');
const Episode = sequelize.define('Episode', {
title: {
type: DataTypes.STRING,
},
number: {
type: DataTypes.INTEGER,
},
})
module.exports = Episode;
mi sequelize config file:
const { Sequelize } = require('sequelize');
const sequelize = new Sequelize({
dialect: 'sqlite',
storage: 'database.sqlite', // Nombre y ubicación del archivo de la base de datos SQLite
logging: console.log, // Para mostrar las consultas SQL que se ejecutan
define: {
timestamps: false, // Deshabilita el uso de createdAt y updatedAt en todos los modelos
},
sync: true
});
module.exports = sequelize;
does anyone can give me a hint?
im also using sqllite!
Beta Was this translation helpful? Give feedback.
All reactions