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',
|
as: 'entries',
|
||||||
});
|
});
|
||||||
|
|
||||||
// * ENTRY & MEDIA - ONE TO MANY
|
// ! MEDIA
|
||||||
// Entry.hasMany(Media, { foreignKey: 'entryId', as: 'medias', onDelete: 'CASCADE', });
|
// * MEDIA & ENTRY - MANY TO ONE
|
||||||
// Media.belongsTo(Entry, { foreignKey: 'entryId', as: 'entry' });
|
|
||||||
|
|
||||||
Media.belongsTo(Entry, {
|
Media.belongsTo(Entry, {
|
||||||
foreignKey: 'mediaableId',
|
foreignKey: 'mediaableId',
|
||||||
as: 'entry',
|
as: 'entry',
|
||||||
@@ -116,15 +114,6 @@ Media.belongsTo(Entry, {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Media.belongsTo(Collection, {
|
|
||||||
foreignKey: 'mediaableId',
|
|
||||||
as: 'collection',
|
|
||||||
constraints: false,
|
|
||||||
where: {
|
|
||||||
mediaable: 'collection'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Entry.hasMany(Media, {
|
Entry.hasMany(Media, {
|
||||||
foreignKey: 'mediaableId',
|
foreignKey: 'mediaableId',
|
||||||
constraints: false,
|
constraints: false,
|
||||||
@@ -132,6 +121,16 @@ Entry.hasMany(Media, {
|
|||||||
scope: { mediaable: 'entry' }
|
scope: { mediaable: 'entry' }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// * MEDIA & Collection - MANY TO ONE
|
||||||
|
Media.belongsTo(Collection, {
|
||||||
|
foreignKey: 'mediaableId',
|
||||||
|
as: 'collection',
|
||||||
|
constraints: false,
|
||||||
|
where: {
|
||||||
|
mediaable: 'collection'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
Collection.hasMany(Media, {
|
Collection.hasMany(Media, {
|
||||||
foreignKey: 'mediaableId',
|
foreignKey: 'mediaableId',
|
||||||
constraints: false,
|
constraints: false,
|
||||||
@@ -139,6 +138,41 @@ Collection.hasMany(Media, {
|
|||||||
scope: { mediaable: 'collection' }
|
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 & SEASON - ONE TO MANY
|
||||||
Entry.hasMany(Season, { foreignKey: 'entry_id', as: 'seasons', onDelete: 'CASCADE', });
|
Entry.hasMany(Season, { foreignKey: 'entry_id', as: 'seasons', onDelete: 'CASCADE', });
|
||||||
Season.belongsTo(Entry, { foreignKey: 'entry_id', as: 'entry' });
|
Season.belongsTo(Entry, { foreignKey: 'entry_id', as: 'entry' });
|
||||||
|
|||||||
Reference in new issue
Block a user