Files
directus/packages/utils/shared/get-relation.ts
Nitwel 4d59d70897 Unify getRelation/getRelations usage across packages (#25053)
* restructure

* add changeset

* add schema builder for primary fields

* fmt

* add relational generation

* add more tests and clean schema.ts

* fmt

* add changeset

* add more tests and tidy up existing ones

* add more tests and clean code

* add standalone a2o relation

* add tests and clean up even more logic

* continue working on tests

* update more tests

* update tests and reorganize files

* more tests and take appart applyFilter

* update test for get-filter-type

* update export

* fmt

* unify get-relations

* fmt

* add changeset

* Update .changeset/dry-donuts-guess.md

* remove additional whitespace

* Update .changeset/dry-donuts-guess.md

* Update .changeset/dry-donuts-guess.md

* fix new test

* chore: organize import

* remove unnecessary type assertion

---------

Co-authored-by: daedalus <44623501+ComfortablyCoding@users.noreply.github.com>
Co-authored-by: ian <licitdev@gmail.com>
2025-04-22 16:59:20 -04:00

24 lines
726 B
TypeScript

import type { Relation } from '@directus/types';
export function getRelations(relations: Relation[], collection: string, field: string) {
const relation = relations.filter((relation) => {
return (
(relation.collection === collection && relation.field === field) ||
(relation.related_collection === collection && relation.meta?.one_field === field)
);
});
return relation;
}
export function getRelation(relations: Relation[], collection: string, field: string) {
const relation = relations.find((relation) => {
return (
(relation.collection === collection && relation.field === field) ||
(relation.related_collection === collection && relation.meta?.one_field === field)
);
});
return relation;
}