Repository: directus/directus
File: app/src/composables/use-item.ts (TypeScript)

Code before:
			...(itemData.data.data || {}),
			...edits.value,
		};

		// Make sure to delete the primary key if it's has auto increment enabled
		if (primaryKeyField.value && primaryKeyField.value.field in newItem) {
			if (primaryKeyField.value.schema?.has_auto_increment || primaryKeyField.value.meta?.special?.includes('uuid')) {
				delete newItem[primaryKeyField.value.field];
			}
		}

		// Make sure to delete nested relational primary keys
		const fieldsStore = useFieldsStore();
		const relationsStore = useRelationsStore();
		const relations = relationsStore.getRelationsForCollection(collection.value);

		for (const relation of relations) {
			const relatedPrimaryKeyField = fieldsStore.getPrimaryKeyFieldForCollection(relation.collection);

			const existsJunctionRelated = relationsStore.relations.find((r) => {
				return r.collection === relation.collection && r.meta?.many_field === relation.meta?.junction_field;
			});

			if (relation.meta?.one_field && relation.meta.one_field in newItem) {
				const fieldsToFetch = fields
					.filter((field) => field.startsWith(relation.meta!.one_field!))
					.map((field) => (field.includes('.') ? field.split('.').slice(1).join('.') : '*'));

				if (Array.isArray(newItem[relation.meta.one_field])) {
					const existingItems = await findExistingRelatedItems(
						newItem,
						relation,
						relatedPrimaryKeyField,
						fieldsToFetch,
					);

					newItem[relation.meta.one_field] = newItem[relation.meta.one_field].map((relatedItem: any) => {
						if (typeof relatedItem !== 'object' && existingItems.length > 0) {
							relatedItem = existingItems.find((existingItem: any) => existingItem.id === relatedItem);
						}

						delete relatedItem[relatedPrimaryKeyField!.field];

						updateJunctionRelatedKey(relation, existsJunctionRelated, fieldsStore, relatedItem);
						return relatedItem;
					});
				} else {
					const createdRelatedItems = newItem[relation.meta.one_field]?.create;
					const updatedRelatedItems = newItem[relation.meta.one_field]?.update;
					const deletedRelatedItems = newItem[relation.meta.one_field]?.delete;


Review comment (refactor):
I've not found any issue with this fix, but noticed an oddity with the use of `field.startsWith()` for filtering. 
Eg: `m2m` and `m2m_other` both start with `m2m`, resulting in duplicate fields requested. 

It might need to be updated to be more specific or it could be an issue with my local schema. 🤔 
Will have to investigate further, but it's probably out of the PR's scope.  

Code after:
			...(itemData.data.data || {}),
			...edits.value,
		};

		// Make sure to delete the primary key if it's has auto increment enabled
		if (primaryKeyField.value && primaryKeyField.value.field in newItem) {
			if (primaryKeyField.value.schema?.has_auto_increment || primaryKeyField.value.meta?.special?.includes('uuid')) {
				delete newItem[primaryKeyField.value.field];
			}
		}

		// Make sure to delete nested relational primary keys
		const fieldsStore = useFieldsStore();
		const relationsStore = useRelationsStore();
		const relations = relationsStore.getRelationsForCollection(collection.value);

		for (const relation of relations) {
			const relatedPrimaryKeyField = fieldsStore.getPrimaryKeyFieldForCollection(relation.collection);

			const existsJunctionRelated = relationsStore.relations.find((r) => {
				return r.collection === relation.collection && r.meta?.many_field === relation.meta?.junction_field;
			});

			const oneField = relation.meta?.one_field;

			if (oneField && oneField in newItem) {
				const fieldsToFetch = fields
					.filter((field) => field.split('.')[0] === oneField || field === '*')
					.map((field) => (field.includes('.') ? field.split('.').slice(1).join('.') : '*'));

				if (Array.isArray(newItem[oneField])) {
					const existingItems = await findExistingRelatedItems(
						newItem,
						relation,
						relatedPrimaryKeyField,
						fieldsToFetch,
					);

					newItem[oneField] = newItem[oneField].map((relatedItem: any) => {
						if (typeof relatedItem !== 'object' && existingItems.length > 0) {
							relatedItem = existingItems.find((existingItem: any) => existingItem.id === relatedItem);
						}

						delete relatedItem[relatedPrimaryKeyField!.field];

						updateJunctionRelatedKey(relation, existsJunctionRelated, fieldsStore, relatedItem);
						return relatedItem;
					});
				} else {
					const createdRelatedItems = newItem[oneField]?.create;
					const updatedRelatedItems = newItem[oneField]?.update;