From 10a9dd4f194b62d2d98347ca4c0d2d76abe06a97 Mon Sep 17 00:00:00 2001 From: Oreille <33065839+Oreilles@users.noreply.github.com> Date: Wed, 24 Nov 2021 22:15:35 +0100 Subject: [PATCH] Also return the junction collection in getRelatedCollection (#9890) --- .../related-values/related-values.vue | 20 +++++++++++++++++-- .../get-related-collection.ts | 2 ++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/src/displays/related-values/related-values.vue b/app/src/displays/related-values/related-values.vue index 512a8fc970..d665d1677b 100644 --- a/app/src/displays/related-values/related-values.vue +++ b/app/src/displays/related-values/related-values.vue @@ -18,7 +18,11 @@ - + @@ -69,6 +73,10 @@ export default defineComponent({ return relatedCollectionData.value.relatedCollection; }); + const junctionCollection = computed(() => { + return relatedCollectionData.value.junctionCollection; + }); + const localType = computed(() => { return getLocalTypeForField(props.collection, props.field); }); @@ -105,7 +113,15 @@ export default defineComponent({ return null; }); - return { relatedCollection, primaryKeyFieldPath, getLinkForItem, internalTemplate, unit, localType }; + return { + relatedCollection, + junctionCollection, + primaryKeyFieldPath, + getLinkForItem, + internalTemplate, + unit, + localType, + }; function getLinkForItem(item: any) { if (!relatedCollectionData.value || !primaryKeyFieldPath.value) return null; diff --git a/app/src/utils/get-related-collection/get-related-collection.ts b/app/src/utils/get-related-collection/get-related-collection.ts index 2273b3d1b0..24241e8163 100644 --- a/app/src/utils/get-related-collection/get-related-collection.ts +++ b/app/src/utils/get-related-collection/get-related-collection.ts @@ -4,6 +4,7 @@ import { getLocalTypeForField } from '../../modules/settings/routes/data-model/g export interface RelatedCollectionData { relatedCollection: string; + junctionCollection?: string; path?: string[]; } @@ -18,6 +19,7 @@ export default function getRelatedCollection(collection: string, field: string): if (localType == 'm2m' && relations.length > 1) { return { relatedCollection: relations[1].related_collection!, + junctionCollection: relations[0].collection, path: [relations[1].field], }; }