diff --git a/specifyweb/frontend/js_src/lib/components/DataModel/resource.ts b/specifyweb/frontend/js_src/lib/components/DataModel/resource.ts index 9928fcf4bde..d66501430cf 100644 --- a/specifyweb/frontend/js_src/lib/components/DataModel/resource.ts +++ b/specifyweb/frontend/js_src/lib/components/DataModel/resource.ts @@ -6,12 +6,18 @@ import { f } from '../../utils/functools'; import type { DeepPartial, RA, RR } from '../../utils/types'; import { defined, filterArray } from '../../utils/types'; import { keysToLowerCase, removeKey } from '../../utils/utils'; +import type { InteractionWithPreps } from '../Interactions/helpers'; +import { + interactionPrepTables, + interactionsWithPrepTables, +} from '../Interactions/helpers'; import { userPreferences } from '../Preferences/userPreferences'; import { formatUrl } from '../Router/queryString'; import { relationshipIsToMany } from '../WbPlanView/mappingHelpers'; import { addMissingFields } from './addMissingFields'; import { getFieldsFromPath } from './businessRules'; import type { + AnyInteractionPreparation, AnySchema, SerializedRecord, SerializedResource, @@ -293,6 +299,22 @@ export const getUniqueFields = (table: SpecifyTable): RA => ...table.relationships .filter(({ relatedTable }) => relatedTable.name.endsWith('Attachment')) .map(({ name }) => name), + /* + * Interaction Preparations should be considered unique for each + * Interaction + * See https://github.com/specify/specify7/issues/4012 + */ + ...table.relationships + .filter( + ({ relatedTable }) => + interactionsWithPrepTables.includes( + table.name as InteractionWithPreps['tableName'] + ) && + interactionPrepTables.includes( + relatedTable.name as AnyInteractionPreparation['tableName'] + ) + ) + .map(({ name }) => name), ...filterArray( uniqueFields.map((fieldName) => table.getField(fieldName)?.name) ),