Fix broken preset (#12469) (#16119)

This commit is contained in:
Jan Arends
2022-10-24 20:42:54 +02:00
committed by GitHub
parent efe7dce5bc
commit 51bb1f6464
4 changed files with 27 additions and 10 deletions

View File

@@ -79,3 +79,11 @@ test('Returns M2O from related_collection rather than collection', () => {
relatedCollection: 'articles',
});
});
test('Returns null if no relation exists in the relationsStore', () => {
const relationsStore = useRelationsStore();
(relationsStore.getRelationsForField as Mock).mockReturnValue([]);
expect(getRelatedCollection('users', 'favorite_article')).toEqual(null);
});

View File

@@ -14,12 +14,15 @@ export interface RelatedCollectionData {
*
* @param collection - Name of the current parent collection
* @param field - Name of the relational field in the current collection
* @returns Related collection name(s)
* @returns Related collection name(s) or null if no related collection exists in the relationsStore
*/
export function getRelatedCollection(collection: string, field: string): RelatedCollectionData {
export function getRelatedCollection(collection: string, field: string): RelatedCollectionData | null {
const relationsStore = useRelationsStore();
const relations: Relation[] = relationsStore.getRelationsForField(collection, field);
if (relations.length === 0) return null;
const localType = getLocalTypeForField(collection, field);
const o2mTypes = ['o2m', 'm2m', 'm2a', 'translations', 'files'];