Added and configured sequelize
This commit is contained in:
1 parent
772db77e98
commit
bf288d5ab7
2 files changed
+46
No files matched your search
@@ -0,0 +1,8 @@
|
|||||||
|
const { Sequelize } = require('sequelize');
|
||||||
|
|
||||||
|
const sequelize = new Sequelize('Showzy', 'root', 'password', {
|
||||||
|
host: 'localhost',
|
||||||
|
dialect: 'mysql'
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = sequelize;
|
||||||
@@ -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' });
|
||||||
Reference in new issue
Block a user