changed folder structure and added readme file
This commit is contained in:
1 parent
cbdffb21e3
commit
3bb0935db9
50 files changed
+6600
-3999
No files matched your search
@@ -0,0 +1,142 @@
|
||||
// Import models
|
||||
const Franchise = require('../models/Franchise');
|
||||
const Entry = require('../models/Entry')
|
||||
const EntryId = require('../models/EntryId')
|
||||
const EntryRating = require('../models/EntryRating')
|
||||
const EntrySeen = require('../models/EntrySeen');
|
||||
const Collection = require('../models/Collection');
|
||||
const UserCollectionEntry = require('../models/UserCollectionEntry');
|
||||
const Season = require('../models/Season');
|
||||
const Episode = require('../models/Episode');
|
||||
const EpisodeSeen = require('../models/EpisodeSeen');
|
||||
const Genre = require('../models/Genre');
|
||||
const EntryGenre = require('../models/EntryGenre');
|
||||
const Media = require('../models/Media');
|
||||
|
||||
|
||||
// ? 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
|
||||
|
||||
|
||||
// * ENTRY & EntryId - ONE TO ONE
|
||||
Entry.hasOne(EntryId, {
|
||||
foreignKey: 'entry_id', as: 'entryId', onDelete: 'CASCADE',
|
||||
});
|
||||
EntryId.belongsTo(Entry, { foreignKey: 'entry_id', as: 'entry' });
|
||||
|
||||
// * ENTRY & EntryRating - ONE TO ONE
|
||||
Entry.hasOne(EntryRating, {
|
||||
foreignKey: 'entry_id', as: 'entryRating', onDelete: 'CASCADE',
|
||||
});
|
||||
EntryRating.belongsTo(Entry, { foreignKey: 'entry_id', as: 'entry' });
|
||||
|
||||
// * ENTRY & ENTRY_SEEN - ONE TO MANY
|
||||
Entry.hasMany(EntrySeen, {
|
||||
foreignKey: 'entry_id', as: 'entrySeen', onDelete: 'CASCADE',
|
||||
});
|
||||
EntrySeen.belongsTo(Entry, { foreignKey: 'entry_id', as: 'entry' });
|
||||
|
||||
// * ENTRY & LIST - MANY TO MANY
|
||||
Entry.belongsToMany(Collection, {
|
||||
through: UserCollectionEntry,
|
||||
foreignKey: 'entry_id',
|
||||
otherKey: 'user_collection_id',
|
||||
onDelete: 'CASCADE',
|
||||
as: 'collections',
|
||||
});
|
||||
|
||||
Collection.belongsToMany(Entry, {
|
||||
through: UserCollectionEntry,
|
||||
foreignKey: 'user_collection_id',
|
||||
otherKey: 'entry_id',
|
||||
onDelete: 'CASCADE',
|
||||
as: 'entries',
|
||||
});
|
||||
|
||||
Entry.hasMany(UserCollectionEntry, { foreignKey: 'entry_id', as: 'userCollectionEntries' });
|
||||
UserCollectionEntry.belongsTo(Entry, { foreignKey: 'entry_id', as: 'entry' });
|
||||
Collection.hasMany(UserCollectionEntry, { foreignKey: 'user_collection_id', as: 'userCollectionEntries' });
|
||||
UserCollectionEntry.belongsTo(Collection, { foreignKey: 'user_collection_id', as: 'userCollection' });
|
||||
|
||||
// * ENTRY & GENRE - MANY TO MANY
|
||||
Entry.belongsToMany(Genre, {
|
||||
through: EntryGenre,
|
||||
foreignKey: 'entry_id',
|
||||
otherKey: 'genre_id',
|
||||
onDelete: 'CASCADE',
|
||||
as: 'genres',
|
||||
});
|
||||
|
||||
Genre.belongsToMany(Entry, {
|
||||
through: EntryGenre,
|
||||
foreignKey: 'genre_id',
|
||||
otherKey: 'entry_id',
|
||||
onDelete: 'CASCADE',
|
||||
as: 'entries',
|
||||
});
|
||||
|
||||
Entry.hasMany(EntryGenre, { foreignKey: 'entry_id', as: 'entryGenres' });
|
||||
EntryGenre.belongsTo(Entry, { foreignKey: 'entry_id', as: 'entry' });
|
||||
Genre.hasMany(EntryGenre, { foreignKey: 'genre_id', as: 'entryGenres' });
|
||||
EntryGenre.belongsTo(Genre, { foreignKey: 'genre_id', as: 'genre' });
|
||||
|
||||
|
||||
// * ENTRY & MEDIA - ONE TO MANY
|
||||
// Entry.hasMany(Media, { foreignKey: 'entryId', as: 'medias', onDelete: 'CASCADE', });
|
||||
// Media.belongsTo(Entry, { foreignKey: 'entryId', as: 'entry' });
|
||||
|
||||
Media.belongsTo(Entry, {
|
||||
foreignKey: 'mediaableId',
|
||||
as: 'entry',
|
||||
constraints: false,
|
||||
where: {
|
||||
mediaable: 'entry'
|
||||
}
|
||||
});
|
||||
|
||||
Media.belongsTo(Collection, {
|
||||
foreignKey: 'mediaableId',
|
||||
as: 'collection',
|
||||
constraints: false,
|
||||
where: {
|
||||
mediaable: 'collection'
|
||||
}
|
||||
});
|
||||
|
||||
Entry.hasMany(Media, {
|
||||
foreignKey: 'mediaableId',
|
||||
constraints: false,
|
||||
as: 'medias',
|
||||
scope: { mediaable: 'entry' }
|
||||
});
|
||||
|
||||
Collection.hasMany(Media, {
|
||||
foreignKey: 'mediaableId',
|
||||
constraints: false,
|
||||
as: 'medias',
|
||||
scope: { mediaable: 'collection' }
|
||||
});
|
||||
|
||||
// * ENTRY & SEASON - ONE TO MANY
|
||||
Entry.hasMany(Season, { foreignKey: 'entry_id', as: 'seasons', onDelete: 'CASCADE', });
|
||||
Season.belongsTo(Entry, { foreignKey: 'entry_id', as: 'entry' });
|
||||
|
||||
// * SEASON & EPISODE - ONE TO MANY
|
||||
Season.hasMany(Episode, { foreignKey: 'season_id', onDelete: 'CASCADE', });
|
||||
Episode.belongsTo(Season, { foreignKey: 'season_id' });
|
||||
|
||||
// * EPISODE & EPISODE_SEEN - ONE TO MANY
|
||||
Episode.hasMany(EpisodeSeen, { foreignKey: 'episode_id', onDelete: 'CASCADE', });
|
||||
EpisodeSeen.belongsTo(Episode, { foreignKey: 'episode_id' });
|
||||
|
||||
// * ENTRY & EPISODE_SEEN - ONE TO MANY
|
||||
Entry.hasMany(EpisodeSeen, { foreignKey: 'entry_id', onDelete: 'CASCADE', });
|
||||
EpisodeSeen.belongsTo(Entry, { foreignKey: 'entry_id' });
|
||||
|
||||
// * ----
|
||||
Franchise.hasMany(Entry, { foreignKey: 'franchise_id' });
|
||||
Entry.belongsTo(Franchise, { foreignKey: 'franchise_id' });
|
||||
Reference in new issue
Block a user