From 17067a5516816b6b3b1006c4248e8ffd9c7d01f6 Mon Sep 17 00:00:00 2001 From: X4Lo Date: Sat, 12 Jul 2025 00:42:08 +0100 Subject: [PATCH] Backend: Created O2M relation between People & Media --- backend/config/relations.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/backend/config/relations.js b/backend/config/relations.js index 084ea54..ffd78a6 100644 --- a/backend/config/relations.js +++ b/backend/config/relations.js @@ -123,6 +123,23 @@ Entry.hasMany(Media, { scope: { mediaable: 'entry' } }); +// * MEDIA & People - MANY TO ONE +Media.belongsTo(People, { + foreignKey: 'mediaableId', + as: 'people', + constraints: false, + where: { + mediaable: 'people' + } +}); + +People.hasMany(Media, { + foreignKey: 'mediaableId', + constraints: false, + as: 'medias', + scope: { mediaable: 'people' } +}); + // * MEDIA & Collection - MANY TO ONE Media.belongsTo(Collection, { foreignKey: 'mediaableId',