add networks + random changes
This commit is contained in:
1 parent
bb36b2bd44
commit
5dc5a023b8
26 files changed
+1399
-1975
No files matched your search
+30
-12
@@ -12,6 +12,8 @@ const EpisodeSeen = require('../models/EpisodeSeen');
|
||||
const Genre = require('../models/Genre');
|
||||
const EntryGenre = require('../models/EntryGenre');
|
||||
const Media = require('../models/Media');
|
||||
const Network = require('../models/Network');
|
||||
const EntryNetwork = require('../models/EntryNetwork');
|
||||
|
||||
|
||||
// ? one to one
|
||||
@@ -84,39 +86,55 @@ 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 & NETWORK - MANY TO MANY
|
||||
Entry.belongsToMany(Network, {
|
||||
through: EntryNetwork,
|
||||
foreignKey: 'entry_id',
|
||||
otherKey: 'network_id',
|
||||
onDelete: 'CASCADE',
|
||||
as: 'networks',
|
||||
});
|
||||
|
||||
Network.belongsToMany(Entry, {
|
||||
through: EntryNetwork,
|
||||
foreignKey: 'network_id',
|
||||
otherKey: 'entry_id',
|
||||
onDelete: 'CASCADE',
|
||||
as: 'entries',
|
||||
});
|
||||
|
||||
// * 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',
|
||||
Media.belongsTo(Entry, {
|
||||
foreignKey: 'mediaableId',
|
||||
as: 'entry',
|
||||
constraints: false,
|
||||
where: {
|
||||
mediaable: 'entry'
|
||||
}
|
||||
});
|
||||
|
||||
Media.belongsTo(Collection, {
|
||||
foreignKey: 'mediaableId',
|
||||
as: 'collection',
|
||||
Media.belongsTo(Collection, {
|
||||
foreignKey: 'mediaableId',
|
||||
as: 'collection',
|
||||
constraints: false,
|
||||
where: {
|
||||
mediaable: 'collection'
|
||||
}
|
||||
});
|
||||
|
||||
Entry.hasMany(Media, {
|
||||
foreignKey: 'mediaableId',
|
||||
constraints: false,
|
||||
Entry.hasMany(Media, {
|
||||
foreignKey: 'mediaableId',
|
||||
constraints: false,
|
||||
as: 'medias',
|
||||
scope: { mediaable: 'entry' }
|
||||
});
|
||||
|
||||
Collection.hasMany(Media, {
|
||||
foreignKey: 'mediaableId',
|
||||
constraints: false,
|
||||
Collection.hasMany(Media, {
|
||||
foreignKey: 'mediaableId',
|
||||
constraints: false,
|
||||
as: 'medias',
|
||||
scope: { mediaable: 'collection' }
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user