diff --git a/backend/db/database.js b/backend/db/database.js new file mode 100644 index 0000000..50551f6 --- /dev/null +++ b/backend/db/database.js @@ -0,0 +1,8 @@ +const { Sequelize } = require('sequelize'); + +const sequelize = new Sequelize('Showzy', 'root', 'password', { + host: 'localhost', + dialect: 'mysql' +}); + +module.exports = sequelize; \ No newline at end of file diff --git a/backend/db/relations.js b/backend/db/relations.js new file mode 100644 index 0000000..87dbec1 --- /dev/null +++ b/backend/db/relations.js @@ -0,0 +1,38 @@ +// Import models +// const Persons = require('../models/Person') +const Entry = require('../models/Entry') +const EntryId = require('../models/EntryId') +const EntryRating = require('../models/EntryRating') +const Collection = require('../models/Collection') + + +// ? one to one +// A hasOne B = A > B +// A belongsTo B = A < B +// ? one to many +// A hasMany B = A > B +// A belongsTo B = A < B + +// Define associations here +Entry.hasOne(EntryId, { + foreignKey: 'entry_id', + as: 'entryId' +}); +EntryId.belongsTo(Entry, { + foreignKey: 'entry_id', + as: 'entry' +}); + + +Entry.hasOne(EntryRating, { + foreignKey: 'entry_id', + as: 'entryRating' +}); +EntryRating.belongsTo(Entry, { + foreignKey: 'entry_id', + as: 'entry' +}); + + +Collection.hasMany(Entry, { foreignKey: 'collection_id' }); +Entry.belongsTo(Collection, { foreignKey: 'collection_id' }); \ No newline at end of file