I have several tables that have the same structure, they all have a title, description, topic and microtopic but they have different content. I want to display the table information according to the page I am using a single Model.
On this site I will have a page with several categories such as: Movies, music and series. Each category will have a topic, for example, Movies will have: Action, horror, adventure. And each topic will have a microtopic, for example the Film category that has the Action topic will have the following microtopics: Old, current, future releases. And within each microtopic you will have a list containing movies with their title, description, topic and microtopic corresponding to that search.
I would like to know how I could carry out this process. I have here an example of a model that I created and what I imagined would be to change the tableName according to the url but I didn’t find a way to do that.
I leave here the example of the model I created:
import {Model, DataTypes} from 'sequelize';
import {sequelize} from '../instances/mysql';
export interface ContentInstance extends Model{
id: number,
title: string,
description: string,
topic: string,
microtopic: string,
};
export const Content= sequelize.define<ContentInstance>("Content", {
id:{
primaryKey: true,
autoIncrement: true,
type: DataTypes.INTEGER
},
title:{
type: DataTypes.STRING,
},
description:{
type: DataTypes.STRING,
},
topic:{
type: DataTypes.STRING
},
microtopic:{
type: DataTypes.STRING
}
}, {
tableName: 'actionold', //I imagined something like concatenating topic + microtopic but dinamically
timestamps: false
});
I’m new to backend and Node.Js (and I’m using mySQL)