Also return the junction collection in getRelatedCollection (#9890)

This commit is contained in:
Oreille
2021-11-24 22:15:35 +01:00
committed by GitHub
parent 25375cc481
commit 10a9dd4f19
2 changed files with 20 additions and 2 deletions

View File

@@ -18,7 +18,11 @@
<v-list class="links">
<v-list-item v-for="item in value" :key="item[primaryKeyFieldPath]">
<v-list-item-content>
<render-template :template="internalTemplate" :item="item" :collection="relatedCollection" />
<render-template
:template="internalTemplate"
:item="item"
:collection="junctionCollection ?? relatedCollection"
/>
</v-list-item-content>
<v-list-item-icon>
<router-link :to="getLinkForItem(item)"><v-icon name="launch" small /></router-link>
@@ -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;

View File

@@ -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],
};
}