Create associations

This commit is contained in:
baz 2023-12-18 21:56:59 +00:00
parent 2e4e68a82b
commit 590ca18f18
1 changed files with 22 additions and 0 deletions

22
dbObjects.js Normal file
View File

@ -0,0 +1,22 @@
const Sequelize = require('sequelize');
const sequelize = new Sequelize('database', 'username', 'password', {
host: 'localhost',
dialect: 'sqlite',
logging: false,
storage: 'database.sqlite',
});
const Users = require('./models/users.js')(sequelize, Sequelize.DataTypes);
const Games = require('./models/games.js')(sequelize, Sequelize.DataTypes);
const BeatenGames = require('./models/beatenGames.js')(sequelize, Sequelize.DataTypes);
// Create userId foreignKey
Users.hasMany(BeatenGames);
BeatenGames.belongsTo(Users);
// Create gameId foreignKey
Games.hasMany(BeatenGames);
BeatenGames.belongsTo(Games);
module.exports = { Users, Games, BeatenGames };