mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Rename relations
This commit is contained in:
@@ -13,8 +13,7 @@ export default function useFieldTree(collection: Ref<string>) {
|
||||
return fieldsStore
|
||||
.getFieldsForCollection(collection.value)
|
||||
.filter(
|
||||
(field: Field) =>
|
||||
field.system?.hidden === false && field.system?.special?.toLowerCase() !== 'alias'
|
||||
(field: Field) => field.system?.hidden === false && field.system?.special?.toLowerCase() !== 'alias'
|
||||
)
|
||||
.map((field: Field) => parseField(field, []));
|
||||
|
||||
@@ -34,9 +33,9 @@ export default function useFieldTree(collection: Ref<string>) {
|
||||
const relatedFields = relations
|
||||
.map((relation: Relation) => {
|
||||
const relatedCollection =
|
||||
relation.collection_many === field.collection
|
||||
? relation.collection_one
|
||||
: relation.collection_many;
|
||||
relation.many_collection === field.collection
|
||||
? relation.one_collection
|
||||
: relation.many_collection;
|
||||
|
||||
if (relation.junction_field === field.field) return [];
|
||||
|
||||
@@ -44,8 +43,7 @@ export default function useFieldTree(collection: Ref<string>) {
|
||||
.getFieldsForCollection(relatedCollection)
|
||||
.filter(
|
||||
(field: Field) =>
|
||||
field.system?.hidden === false &&
|
||||
field.system?.special?.toLowerCase() !== 'alias'
|
||||
field.system?.hidden === false && field.system?.special?.toLowerCase() !== 'alias'
|
||||
);
|
||||
})
|
||||
.flat()
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
<modal-browse
|
||||
v-if="!disabled"
|
||||
:active.sync="showBrowseModal"
|
||||
:collection="relationJunctionToRelated.collection_one"
|
||||
:collection="relationJunctionToRelated.one_collection"
|
||||
:selection="[]"
|
||||
:filters="selectionFilters"
|
||||
@input="stageSelection"
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
<modal-browse
|
||||
v-if="!disabled"
|
||||
:active.sync="showBrowseModal"
|
||||
:collection="relationJunctionToRelated.collection_one"
|
||||
:collection="relationJunctionToRelated.one_collection"
|
||||
:selection="[]"
|
||||
:filters="selectionFilters"
|
||||
@input="stageSelection"
|
||||
|
||||
@@ -104,7 +104,7 @@ export default function usePreview({
|
||||
// yet, as they can't have been saved yet.
|
||||
if (primaryKey.value === '+') return [];
|
||||
|
||||
const junctionTable = relationCurrentToJunction.value.collection_many;
|
||||
const junctionTable = relationCurrentToJunction.value.many_collection;
|
||||
|
||||
// The stuff we want to fetch is the related junction row, and the content of the
|
||||
// deeply related item nested. This should match the value that's set in the fields
|
||||
|
||||
@@ -19,7 +19,7 @@ export default function useRelation({ collection, field }: RelationParams) {
|
||||
|
||||
const relationCurrentToJunction = computed(() => {
|
||||
return relations.value.find(
|
||||
(relation: Relation) => relation.collection_one === collection.value && relation.field_one === field.value
|
||||
(relation: Relation) => relation.one_collection === collection.value && relation.one_field === field.value
|
||||
);
|
||||
});
|
||||
|
||||
@@ -30,8 +30,8 @@ export default function useRelation({ collection, field }: RelationParams) {
|
||||
return relations.value[index];
|
||||
});
|
||||
|
||||
const junctionCollection = computed(() => relations.value[0].collection_many);
|
||||
const relatedCollection = computed(() => relations.value[1].collection_one);
|
||||
const junctionCollection = computed(() => relations.value[0].many_collection);
|
||||
const relatedCollection = computed(() => relations.value[1].one_collection);
|
||||
|
||||
const { primaryKeyField: junctionCollectionPrimaryKeyField } = useCollection(junctionCollection);
|
||||
const { primaryKeyField: relatedCollectionPrimaryKeyField } = useCollection(relatedCollection);
|
||||
|
||||
@@ -337,7 +337,7 @@ export default defineComponent({
|
||||
|
||||
const relatedCollection = computed(() => {
|
||||
if (!relation.value) return null;
|
||||
return collectionsStore.getCollection(relation.value.collection_one);
|
||||
return collectionsStore.getCollection(relation.value.one_collection);
|
||||
});
|
||||
|
||||
const { collection } = toRefs(relatedCollection.value);
|
||||
|
||||
@@ -139,7 +139,7 @@ export default defineComponent({
|
||||
|
||||
const relatedCollection = computed(() => {
|
||||
if (!relation.value) return null;
|
||||
return collectionsStore.getCollection(relation.value.collection_many);
|
||||
return collectionsStore.getCollection(relation.value.many_collection);
|
||||
});
|
||||
|
||||
const { collection } = toRefs(relatedCollection.value);
|
||||
@@ -253,7 +253,7 @@ export default defineComponent({
|
||||
return item;
|
||||
})
|
||||
.filter((item) => item.hasOwnProperty(pkField))
|
||||
.filter((item) => item[relation.value.field_many] !== null);
|
||||
.filter((item) => item[relation.value.many_field] !== null);
|
||||
|
||||
const newlyAddedItems = changes.filter(
|
||||
(change) =>
|
||||
@@ -474,7 +474,7 @@ export default defineComponent({
|
||||
return emit('input', [
|
||||
{
|
||||
[pkField]: itemPrimaryKey,
|
||||
[relation.value.field_many]: null,
|
||||
[relation.value.many_field]: null,
|
||||
},
|
||||
]);
|
||||
}
|
||||
@@ -505,7 +505,7 @@ export default defineComponent({
|
||||
if (stagedValue[pkField] === itemPrimaryKey) {
|
||||
return {
|
||||
[pkField]: itemPrimaryKey,
|
||||
[relation.value.field_many]: null,
|
||||
[relation.value.many_field]: null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -518,7 +518,7 @@ export default defineComponent({
|
||||
...props.value,
|
||||
{
|
||||
[pkField]: itemPrimaryKey,
|
||||
[relation.value.field_many]: null,
|
||||
[relation.value.many_field]: null,
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ export default defineComponent({
|
||||
|
||||
const relatedCollection = computed(() => {
|
||||
if (!relation.value) return null;
|
||||
return collectionsStore.getCollection(relation.value.collection_many);
|
||||
return collectionsStore.getCollection(relation.value.many_collection);
|
||||
});
|
||||
|
||||
const { collection } = toRefs(relatedCollection.value);
|
||||
|
||||
@@ -230,7 +230,7 @@ export default defineComponent({
|
||||
if (field.field === '$file') return true;
|
||||
return !!relationsStore.state.relations.find((relation) => {
|
||||
return (
|
||||
relation.collection_many === props.collection && relation.collection_one === 'directus_files'
|
||||
relation.many_collection === props.collection && relation.one_collection === 'directus_files'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -12,14 +12,14 @@
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="type-label">{{ $t('related_collection') }}</div>
|
||||
<v-select :disabled="type === 'files'" :items="collectionItems" v-model="relations[1].collection_one" />
|
||||
<v-select :disabled="type === 'files'" :items="collectionItems" v-model="relations[1].one_collection" />
|
||||
</div>
|
||||
<v-input disabled :value="relations[0].primary_one" />
|
||||
<v-select :disabled="!junctionCollection" :items="junctionFields" v-model="relations[0].field_many" />
|
||||
<v-input disabled :value="relations[0].one_primary" />
|
||||
<v-select :disabled="!junctionCollection" :items="junctionFields" v-model="relations[0].many_field" />
|
||||
<div class="spacer" />
|
||||
<div class="spacer" />
|
||||
<v-select :disabled="!junctionCollection" :items="junctionFields" v-model="relations[1].field_many" />
|
||||
<v-input disabled :value="relations[1].primary_one" />
|
||||
<v-select :disabled="!junctionCollection" :items="junctionFields" v-model="relations[1].many_field" />
|
||||
<v-input disabled :value="relations[1].one_primary" />
|
||||
<v-icon name="arrow_forward" />
|
||||
<v-icon name="arrow_backward" />
|
||||
</div>
|
||||
@@ -73,11 +73,11 @@ export default defineComponent({
|
||||
|
||||
const junctionCollection = computed({
|
||||
get() {
|
||||
return state.relations[0].collection_many;
|
||||
return state.relations[0].many_collection;
|
||||
},
|
||||
set(collection: string) {
|
||||
state.relations[0].collection_many = collection;
|
||||
state.relations[1].collection_many = collection;
|
||||
state.relations[0].many_collection = collection;
|
||||
state.relations[1].many_collection = collection;
|
||||
},
|
||||
});
|
||||
|
||||
@@ -88,7 +88,7 @@ export default defineComponent({
|
||||
text: field.field,
|
||||
value: field.field,
|
||||
disabled:
|
||||
state.relations[0].field_many === field.field || state.relations[1].field_many === field.field,
|
||||
state.relations[0].many_field === field.field || state.relations[1].many_field === field.field,
|
||||
}));
|
||||
});
|
||||
|
||||
|
||||
@@ -4,14 +4,14 @@
|
||||
<div class="grid">
|
||||
<div class="field">
|
||||
<div class="type-label">{{ $t('this_collection') }}</div>
|
||||
<v-input disabled :value="relations[0].collection_many" />
|
||||
<v-input disabled :value="relations[0].many_collection" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="type-label">{{ $t('related_collection') }}</div>
|
||||
<v-select
|
||||
:placeholder="$t('choose_a_collection')"
|
||||
:items="items"
|
||||
v-model="relations[0].collection_one"
|
||||
v-model="relations[0].one_collection"
|
||||
/>
|
||||
</div>
|
||||
<v-input disabled :value="fieldData.field" />
|
||||
@@ -97,8 +97,8 @@ export default defineComponent({
|
||||
);
|
||||
|
||||
const relatedPrimary = computed(() => {
|
||||
return state.relations[0].collection_one
|
||||
? fieldsStore.getPrimaryKeyFieldForCollection(state.relations[0].collection_one)?.field
|
||||
return state.relations[0].one_collection
|
||||
? fieldsStore.getPrimaryKeyFieldForCollection(state.relations[0].one_collection)?.field
|
||||
: null;
|
||||
});
|
||||
|
||||
@@ -115,7 +115,7 @@ export default defineComponent({
|
||||
state.newFields = [
|
||||
{
|
||||
field: '',
|
||||
collection: state.relations[0].collection_one,
|
||||
collection: state.relations[0].one_collection,
|
||||
system: {
|
||||
special: 'o2m',
|
||||
interface: 'one-to-many',
|
||||
@@ -143,15 +143,15 @@ export default defineComponent({
|
||||
state.relations = [
|
||||
{
|
||||
...state.relations[0],
|
||||
field_one: field,
|
||||
one_field: field,
|
||||
},
|
||||
];
|
||||
},
|
||||
});
|
||||
|
||||
const correspondingLabel = computed(() => {
|
||||
if (state.relations[0].collection_one) {
|
||||
return i18n.t('add_o2m_to_collection', { collection: state.relations[0].collection_one });
|
||||
if (state.relations[0].one_collection) {
|
||||
return i18n.t('add_o2m_to_collection', { collection: state.relations[0].one_collection });
|
||||
}
|
||||
|
||||
return i18n.t('add_field_related');
|
||||
|
||||
@@ -12,10 +12,10 @@
|
||||
</div>
|
||||
<v-input disabled :value="currentCollectionPrimaryKey.field" />
|
||||
<v-select
|
||||
v-model="relations[0].field_many"
|
||||
:disabled="!relations[0].collection_many"
|
||||
v-model="relations[0].many_field"
|
||||
:disabled="!relations[0].many_collection"
|
||||
:items="fields"
|
||||
:placeholder="!relations[0].collection_many ? $t('choose_a_collection') : $t('choose_a_field')"
|
||||
:placeholder="!relations[0].many_collection ? $t('choose_a_collection') : $t('choose_a_field')"
|
||||
/>
|
||||
<v-icon name="arrow_forward" />
|
||||
</div>
|
||||
@@ -79,11 +79,11 @@ export default defineComponent({
|
||||
);
|
||||
|
||||
const fields = computed(() => {
|
||||
if (!state.relations[0].collection_many) return [];
|
||||
if (!state.relations[0].many_collection) return [];
|
||||
|
||||
return fieldsStore.state.fields
|
||||
.filter((field) => {
|
||||
if (field.collection !== state.relations[0].collection_many) return false;
|
||||
if (field.collection !== state.relations[0].many_collection) return false;
|
||||
|
||||
// Make sure the selected field matches the type of primary key of the current
|
||||
// collection. Otherwise you aren't able to properly save the primary key
|
||||
@@ -96,11 +96,11 @@ export default defineComponent({
|
||||
|
||||
const collectionMany = computed({
|
||||
get() {
|
||||
return state.relations[0].collection_many!;
|
||||
return state.relations[0].many_collection!;
|
||||
},
|
||||
set(collection: string) {
|
||||
state.relations[0].collection_many = collection;
|
||||
state.relations[0].field_many = '';
|
||||
state.relations[0].many_collection = collection;
|
||||
state.relations[0].many_field = '';
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -185,21 +185,21 @@ export default defineComponent({
|
||||
if (['o2m', 'm2o', 'file'].includes(localType.value)) {
|
||||
return (
|
||||
state.relations.length === 0 ||
|
||||
isEmpty(state.relations[0].collection_many) ||
|
||||
isEmpty(state.relations[0].field_many) ||
|
||||
isEmpty(state.relations[0].collection_one)
|
||||
isEmpty(state.relations[0].many_collection) ||
|
||||
isEmpty(state.relations[0].many_field) ||
|
||||
isEmpty(state.relations[0].one_collection)
|
||||
);
|
||||
}
|
||||
|
||||
if (['m2m', 'files'].includes(localType.value)) {
|
||||
return (
|
||||
state.relations.length !== 2 ||
|
||||
isEmpty(state.relations[0].collection_many) ||
|
||||
isEmpty(state.relations[0].field_many) ||
|
||||
isEmpty(state.relations[0].field_one) ||
|
||||
isEmpty(state.relations[1].collection_many) ||
|
||||
isEmpty(state.relations[1].field_many) ||
|
||||
isEmpty(state.relations[1].collection_one)
|
||||
isEmpty(state.relations[0].many_collection) ||
|
||||
isEmpty(state.relations[0].many_field) ||
|
||||
isEmpty(state.relations[0].one_field) ||
|
||||
isEmpty(state.relations[1].many_collection) ||
|
||||
isEmpty(state.relations[1].many_field) ||
|
||||
isEmpty(state.relations[1].one_collection)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -258,15 +258,15 @@ export default defineComponent({
|
||||
|
||||
if (relations.length === 1) {
|
||||
const relation = relations[0];
|
||||
if (relation.collection_one === 'directus_files') return 'file';
|
||||
if (relation.collection_many === collection) return 'm2o';
|
||||
if (relation.one_collection === 'directus_files') return 'file';
|
||||
if (relation.many_collection === collection) return 'm2o';
|
||||
return 'o2m';
|
||||
}
|
||||
|
||||
if (relations.length === 2) {
|
||||
if (
|
||||
relations[0].collection_one === 'directus_files' ||
|
||||
relations[1].collection_one === 'directus_files'
|
||||
relations[0].one_collection === 'directus_files' ||
|
||||
relations[1].one_collection === 'directus_files'
|
||||
) {
|
||||
return 'files';
|
||||
} else {
|
||||
|
||||
@@ -62,11 +62,11 @@ function initLocalStore(
|
||||
|
||||
state.relations = [
|
||||
{
|
||||
collection_many: collection,
|
||||
field_many: '',
|
||||
primary_many: fieldsStore.getPrimaryKeyFieldForCollection(collection)?.field,
|
||||
collection_one: 'directus_files',
|
||||
primary_one: fieldsStore.getPrimaryKeyFieldForCollection('directus_files')?.field,
|
||||
many_collection: collection,
|
||||
many_field: '',
|
||||
many_primary: fieldsStore.getPrimaryKeyFieldForCollection(collection)?.field,
|
||||
one_collection: 'directus_files',
|
||||
one_primary: fieldsStore.getPrimaryKeyFieldForCollection('directus_files')?.field,
|
||||
},
|
||||
];
|
||||
}
|
||||
@@ -74,7 +74,7 @@ function initLocalStore(
|
||||
watch(
|
||||
() => state.fieldData.field,
|
||||
() => {
|
||||
state.relations[0].field_many = state.fieldData.field;
|
||||
state.relations[0].many_field = state.fieldData.field;
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -83,11 +83,11 @@ function initLocalStore(
|
||||
if (!isExisting) {
|
||||
state.relations = [
|
||||
{
|
||||
collection_many: collection,
|
||||
field_many: '',
|
||||
primary_many: fieldsStore.getPrimaryKeyFieldForCollection(collection)?.field,
|
||||
collection_one: '',
|
||||
primary_one: fieldsStore.getPrimaryKeyFieldForCollection('directus_files')?.field,
|
||||
many_collection: collection,
|
||||
many_field: '',
|
||||
many_primary: fieldsStore.getPrimaryKeyFieldForCollection(collection)?.field,
|
||||
one_collection: '',
|
||||
one_primary: fieldsStore.getPrimaryKeyFieldForCollection('directus_files')?.field,
|
||||
},
|
||||
];
|
||||
}
|
||||
@@ -95,25 +95,25 @@ function initLocalStore(
|
||||
watch(
|
||||
() => state.fieldData.field,
|
||||
() => {
|
||||
state.relations[0].field_many = state.fieldData.field;
|
||||
state.relations[0].many_field = state.fieldData.field;
|
||||
}
|
||||
);
|
||||
|
||||
// Make sure to keep the current m2o field type in sync with the primary key of the
|
||||
// selected related collection
|
||||
watch(
|
||||
() => state.relations[0].collection_one,
|
||||
() => state.relations[0].one_collection,
|
||||
() => {
|
||||
const field = fieldsStore.getPrimaryKeyFieldForCollection(state.relations[0].collection_one);
|
||||
const field = fieldsStore.getPrimaryKeyFieldForCollection(state.relations[0].one_collection);
|
||||
state.fieldData.type = field.type;
|
||||
}
|
||||
);
|
||||
|
||||
watch(
|
||||
() => state.relations[0].collection_one,
|
||||
() => state.relations[0].one_collection,
|
||||
() => {
|
||||
if (state.newFields.length > 0) {
|
||||
state.newFields[0].collection = state.relations[0].collection_one;
|
||||
state.newFields[0].collection = state.relations[0].one_collection;
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -127,13 +127,13 @@ function initLocalStore(
|
||||
|
||||
state.relations.push = [
|
||||
{
|
||||
collection_many: '',
|
||||
field_many: '',
|
||||
primary_many: '',
|
||||
many_collection: '',
|
||||
many_field: '',
|
||||
many_primary: '',
|
||||
|
||||
collection_one: collection,
|
||||
field_one: state.fieldData.field,
|
||||
primary_one: fieldsStore.getPrimaryKeyFieldForCollection(collection)?.field,
|
||||
one_collection: collection,
|
||||
one_field: state.fieldData.field,
|
||||
one_primary: fieldsStore.getPrimaryKeyFieldForCollection(collection)?.field,
|
||||
},
|
||||
];
|
||||
}
|
||||
@@ -141,15 +141,15 @@ function initLocalStore(
|
||||
watch(
|
||||
() => state.fieldData.field,
|
||||
() => {
|
||||
state.relations[0].field_one = state.fieldData.field;
|
||||
state.relations[0].one_field = state.fieldData.field;
|
||||
}
|
||||
);
|
||||
|
||||
watch(
|
||||
() => state.relations[0].collection_many,
|
||||
() => state.relations[0].many_collection,
|
||||
() => {
|
||||
state.relations[0].primary_many = fieldsStore.getPrimaryKeyFieldForCollection(
|
||||
state.relations[0].collection_many
|
||||
state.relations[0].many_primary = fieldsStore.getPrimaryKeyFieldForCollection(
|
||||
state.relations[0].many_collection
|
||||
).field;
|
||||
}
|
||||
);
|
||||
@@ -163,20 +163,20 @@ function initLocalStore(
|
||||
|
||||
state.relations = [
|
||||
{
|
||||
collection_many: '',
|
||||
field_many: '',
|
||||
primary_many: '',
|
||||
collection_one: collection,
|
||||
field_one: state.fieldData.field,
|
||||
primary_one: fieldsStore.getPrimaryKeyFieldForCollection(collection)?.field,
|
||||
many_collection: '',
|
||||
many_field: '',
|
||||
many_primary: '',
|
||||
one_collection: collection,
|
||||
one_field: state.fieldData.field,
|
||||
one_primary: fieldsStore.getPrimaryKeyFieldForCollection(collection)?.field,
|
||||
},
|
||||
{
|
||||
collection_many: '',
|
||||
field_many: '',
|
||||
primary_many: '',
|
||||
collection_one: type === 'files' ? 'directus_files' : '',
|
||||
field_one: null,
|
||||
primary_one:
|
||||
many_collection: '',
|
||||
many_field: '',
|
||||
many_primary: '',
|
||||
one_collection: type === 'files' ? 'directus_files' : '',
|
||||
one_field: null,
|
||||
one_primary:
|
||||
type === 'files' ? fieldsStore.getPrimaryKeyFieldForCollection('directus_files')?.field : '',
|
||||
},
|
||||
];
|
||||
@@ -185,30 +185,30 @@ function initLocalStore(
|
||||
watch(
|
||||
() => state.fieldData.field,
|
||||
() => {
|
||||
state.relations[0].field_one = state.fieldData.field;
|
||||
state.relations[0].one_field = state.fieldData.field;
|
||||
}
|
||||
);
|
||||
|
||||
watch(
|
||||
() => state.relations[0].collection_many,
|
||||
() => state.relations[0].many_collection,
|
||||
() => {
|
||||
const pkField = fieldsStore.getPrimaryKeyFieldForCollection(state.relations[0].collection_many)?.field;
|
||||
state.relations[0].primary_many = pkField;
|
||||
state.relations[1].primary_many = pkField;
|
||||
const pkField = fieldsStore.getPrimaryKeyFieldForCollection(state.relations[0].many_collection)?.field;
|
||||
state.relations[0].many_primary = pkField;
|
||||
state.relations[1].many_primary = pkField;
|
||||
}
|
||||
);
|
||||
|
||||
watch(
|
||||
() => state.relations[0].field_many,
|
||||
() => state.relations[0].many_field,
|
||||
() => {
|
||||
state.relations[1].junction_field = state.relations[0].field_many;
|
||||
state.relations[1].junction_field = state.relations[0].many_field;
|
||||
}
|
||||
);
|
||||
|
||||
watch(
|
||||
() => state.relations[1].field_many,
|
||||
() => state.relations[1].many_field,
|
||||
() => {
|
||||
state.relations[0].junction_field = state.relations[1].field_many;
|
||||
state.relations[0].junction_field = state.relations[1].many_field;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -290,11 +290,11 @@ export const useFieldsStore = createStore({
|
||||
const parts = fields.split('.');
|
||||
const relationshipForField = relationshipStore
|
||||
.getRelationsForField(collection, parts[0])
|
||||
?.find((relation: Relation) => relation.field_many === parts[0]);
|
||||
?.find((relation: Relation) => relation.many_field === parts[0]);
|
||||
|
||||
if (relationshipForField === undefined) return false;
|
||||
|
||||
const relatedCollection = relationshipForField.collection_one;
|
||||
const relatedCollection = relationshipForField.one_collection;
|
||||
parts.shift();
|
||||
const relatedField = parts.join('.');
|
||||
return this.getField(relatedCollection, relatedField);
|
||||
|
||||
@@ -19,7 +19,7 @@ export const useRelationsStore = createStore({
|
||||
},
|
||||
getRelationsForCollection(collection: string) {
|
||||
return this.state.relations.filter((relation) => {
|
||||
return relation.collection_many === collection || relation.collection_one === collection;
|
||||
return relation.many_collection === collection || relation.one_collection === collection;
|
||||
});
|
||||
},
|
||||
getRelationsForField(collection: string, field: string) {
|
||||
@@ -31,10 +31,10 @@ export const useRelationsStore = createStore({
|
||||
if (fieldInfo.type === 'file') {
|
||||
return [
|
||||
{
|
||||
collection_many: collection,
|
||||
field_many: field,
|
||||
collection_one: 'directus_files',
|
||||
field_one: null,
|
||||
many_collection: collection,
|
||||
many_field: field,
|
||||
one_collection: 'directus_files',
|
||||
one_field: null,
|
||||
junction_field: null,
|
||||
},
|
||||
] as Relation[];
|
||||
@@ -43,17 +43,17 @@ export const useRelationsStore = createStore({
|
||||
if (['user', 'user_created', 'user_updated', 'owner'].includes(fieldInfo.type)) {
|
||||
return [
|
||||
{
|
||||
collection_many: collection,
|
||||
field_many: field,
|
||||
collection_one: 'directus_users',
|
||||
field_one: null,
|
||||
many_collection: collection,
|
||||
many_field: field,
|
||||
one_collection: 'directus_users',
|
||||
one_field: null,
|
||||
junction_field: null,
|
||||
},
|
||||
] as Relation[];
|
||||
}
|
||||
|
||||
const relations = this.getRelationsForCollection(collection).filter((relation: Relation) => {
|
||||
return relation.field_many === field || relation.field_one === field;
|
||||
return relation.many_field === field || relation.one_field === field;
|
||||
});
|
||||
|
||||
if (relations.length > 0) {
|
||||
@@ -65,8 +65,8 @@ export const useRelationsStore = createStore({
|
||||
if (isM2M) {
|
||||
const secondaryRelation = this.state.relations.find((relation) => {
|
||||
return (
|
||||
relation.collection_many === relations[0].collection_many &&
|
||||
relation.field_many === relations[0].junction_field
|
||||
relation.many_collection === relations[0].many_collection &&
|
||||
relation.many_field === relations[0].junction_field
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
export type Relation = {
|
||||
id: number;
|
||||
collection_many: string;
|
||||
field_many: string;
|
||||
primary_many: string;
|
||||
collection_one: string;
|
||||
field_one: null | string;
|
||||
primary_one: string;
|
||||
many_collection: string;
|
||||
many_field: string;
|
||||
many_primary: string;
|
||||
one_collection: string;
|
||||
one_field: null | string;
|
||||
one_primary: string;
|
||||
junction_field: null | string;
|
||||
};
|
||||
|
||||
@@ -13,9 +13,9 @@ export default function getRelatedCollection(collection: string, field: string)
|
||||
let relatedCollection: string | null = null;
|
||||
|
||||
if (['user', 'user_updated', 'owner', 'file', 'm2o'].includes(type)) {
|
||||
relatedCollection = relations[0].collection_one;
|
||||
relatedCollection = relations[0].one_collection;
|
||||
} else if (type === 'o2m') {
|
||||
relatedCollection = relations[0].collection_many;
|
||||
relatedCollection = relations[0].many_collection;
|
||||
}
|
||||
|
||||
return relatedCollection;
|
||||
|
||||
@@ -73,8 +73,7 @@ export default defineComponent({
|
||||
return fieldsStore
|
||||
.getFieldsForCollection(props.collection)
|
||||
.filter(
|
||||
(field: Field) =>
|
||||
field.system?.hidden !== true && field.system?.special?.toLowerCase() !== 'alias'
|
||||
(field: Field) => field.system?.hidden !== true && field.system?.special?.toLowerCase() !== 'alias'
|
||||
)
|
||||
.map((field: Field) => parseField(field, []));
|
||||
|
||||
@@ -94,9 +93,9 @@ export default defineComponent({
|
||||
const relatedFields = relations
|
||||
.map((relation: Relation) => {
|
||||
const relatedCollection =
|
||||
relation.collection_many === field.collection
|
||||
? relation.collection_one
|
||||
: relation.collection_many;
|
||||
relation.many_collection === field.collection
|
||||
? relation.one_collection
|
||||
: relation.many_collection;
|
||||
|
||||
if (relation.junction_field === field.field) return [];
|
||||
|
||||
|
||||
@@ -224,9 +224,9 @@ export default defineComponent({
|
||||
return (
|
||||
relations.find((relation: Relation) => {
|
||||
return (
|
||||
relation.collection_many === props.collection && relation.field_many === props.junctionField
|
||||
relation.many_collection === props.collection && relation.many_field === props.junctionField
|
||||
);
|
||||
})?.collection_one || null
|
||||
})?.one_collection || null
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user