B: Add relation between episode/media and season/media
This commit is contained in:
1 parent
59f5d70f09
commit
197e9443ed
1 file changed
+47
-13
+47
-13
@@ -103,10 +103,8 @@ Network.belongsToMany(Entry, {
|
||||
as: 'entries',
|
||||
});
|
||||
|
||||
// * ENTRY & MEDIA - ONE TO MANY
|
||||
// Entry.hasMany(Media, { foreignKey: 'entryId', as: 'medias', onDelete: 'CASCADE', });
|
||||
// Media.belongsTo(Entry, { foreignKey: 'entryId', as: 'entry' });
|
||||
|
||||
// ! MEDIA
|
||||
// * MEDIA & ENTRY - MANY TO ONE
|
||||
Media.belongsTo(Entry, {
|
||||
foreignKey: 'mediaableId',
|
||||
as: 'entry',
|
||||
@@ -116,15 +114,6 @@ Media.belongsTo(Entry, {
|
||||
}
|
||||
});
|
||||
|
||||
Media.belongsTo(Collection, {
|
||||
foreignKey: 'mediaableId',
|
||||
as: 'collection',
|
||||
constraints: false,
|
||||
where: {
|
||||
mediaable: 'collection'
|
||||
}
|
||||
});
|
||||
|
||||
Entry.hasMany(Media, {
|
||||
foreignKey: 'mediaableId',
|
||||
constraints: false,
|
||||
@@ -132,6 +121,16 @@ Entry.hasMany(Media, {
|
||||
scope: { mediaable: 'entry' }
|
||||
});
|
||||
|
||||
// * MEDIA & Collection - MANY TO ONE
|
||||
Media.belongsTo(Collection, {
|
||||
foreignKey: 'mediaableId',
|
||||
as: 'collection',
|
||||
constraints: false,
|
||||
where: {
|
||||
mediaable: 'collection'
|
||||
}
|
||||
});
|
||||
|
||||
Collection.hasMany(Media, {
|
||||
foreignKey: 'mediaableId',
|
||||
constraints: false,
|
||||
@@ -139,6 +138,41 @@ Collection.hasMany(Media, {
|
||||
scope: { mediaable: 'collection' }
|
||||
});
|
||||
|
||||
// * MEDIA & Season - MANY TO ONE
|
||||
Media.belongsTo(Season, {
|
||||
foreignKey: 'mediaableId',
|
||||
as: 'season',
|
||||
constraints: false,
|
||||
where: {
|
||||
mediaable: 'season'
|
||||
}
|
||||
});
|
||||
|
||||
Season.hasMany(Media, {
|
||||
foreignKey: 'mediaableId',
|
||||
constraints: false,
|
||||
as: 'medias',
|
||||
scope: { mediaable: 'season' }
|
||||
});
|
||||
|
||||
// * MEDIA & Episode - MANY TO ONE
|
||||
Media.belongsTo(Episode, {
|
||||
foreignKey: 'mediaableId',
|
||||
as: 'episode',
|
||||
constraints: false,
|
||||
where: {
|
||||
mediaable: 'episode'
|
||||
}
|
||||
});
|
||||
|
||||
Episode.hasMany(Media, {
|
||||
foreignKey: 'mediaableId',
|
||||
constraints: false,
|
||||
as: 'medias',
|
||||
scope: { mediaable: 'episode' }
|
||||
});
|
||||
// ! MEDIA END
|
||||
|
||||
// * ENTRY & SEASON - ONE TO MANY
|
||||
Entry.hasMany(Season, { foreignKey: 'entry_id', as: 'seasons', onDelete: 'CASCADE', });
|
||||
Season.belongsTo(Entry, { foreignKey: 'entry_id', as: 'entry' });
|
||||
|
||||
Reference in new issue
Block a user