Skip to content

Conversation

charlesBochet
Copy link
Member

@charlesBochet charlesBochet commented Oct 8, 2025

While refactoring SingleRecordPicker to support morph use case, we forgot to QA RelationDetailSection for ManyToOne.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greptile Overview

Summary

This PR fixes a critical bug in the RelationToOneSection assignment functionality that was introduced during a previous refactoring of SingleRecordPicker to support morph use cases. The bug occurred in the `RecordDetailRelationSectionDropdownToOne` component where the `onSubmit` callback was receiving an incorrect data structure.

The issue was that the persistence layer expects a FieldRelationToOneValue which should be an ObjectRecord with an id property (or null), but the code was passing just the recordId string directly. This mismatch caused the relation assignment to fail when users tried to select records in ManyToOne relation dropdowns.

The fix changes line 87 in the component to wrap the recordId in an object with an id property: onSubmit?.({ newValue: { id: selectedMorphItem.recordId } }). This ensures the data structure aligns with what the usePersistField hook expects for relation persistence, allowing the updateOneRecord mutation to properly set the foreign key relationship.

This change is part of Twenty's object-record module, specifically within the record field list components that handle relation management in the record detail view. The fix ensures that the relation picker dropdown properly communicates with the persistence layer when users assign related records.

Important Files Changed

Changed Files
Filename Score Overview
packages/twenty-front/src/modules/object-record/record-field-list/record-detail-section/relation/components/RecordDetailRelationSectionDropdownToOne.tsx 4/5 Fixed data structure passed to onSubmit callback from string to object with id property

Confidence score: 4/5

  • This PR addresses a critical bug with a targeted fix that should restore proper functionality to ManyToOne relation assignment
  • Score reflects the focused nature of the fix and clear understanding of the data structure mismatch that caused the bug
  • Pay close attention to the single modified file to ensure the data structure change properly aligns with the persistence layer expectations

Sequence Diagram

sequenceDiagram
    participant User
    participant RecordDetailRelationSectionDropdownToOne
    participant FieldContext
    participant FieldInputEventContext
    participant useObjectMetadataItem
    participant recordStoreFamilySelector
    participant SingleRecordPicker
    participant useCloseDropdown
    participant useAddNewRecordAndOpenRightDrawer
    participant useSingleRecordPickerOpen

    User->>RecordDetailRelationSectionDropdownToOne: "Click pencil icon to edit relation"
    RecordDetailRelationSectionDropdownToOne->>FieldContext: "Get recordId and fieldDefinition"
    FieldContext-->>RecordDetailRelationSectionDropdownToOne: "Return context data"
    
    RecordDetailRelationSectionDropdownToOne->>useObjectMetadataItem: "Get relation object metadata"
    useObjectMetadataItem-->>RecordDetailRelationSectionDropdownToOne: "Return relationObjectMetadataItem"
    
    RecordDetailRelationSectionDropdownToOne->>recordStoreFamilySelector: "Get current field value"
    recordStoreFamilySelector-->>RecordDetailRelationSectionDropdownToOne: "Return fieldValue"
    
    RecordDetailRelationSectionDropdownToOne->>useSingleRecordPickerOpen: "Open single record picker"
    useSingleRecordPickerOpen-->>SingleRecordPicker: "Display picker with current selection"
    
    User->>SingleRecordPicker: "Select new related record"
    SingleRecordPicker->>RecordDetailRelationSectionDropdownToOne: "Call handleRelationPickerEntitySelected"
    
    RecordDetailRelationSectionDropdownToOne->>useCloseDropdown: "Close dropdown"
    RecordDetailRelationSectionDropdownToOne->>FieldInputEventContext: "Submit new value via onSubmit"
    FieldInputEventContext-->>RecordDetailRelationSectionDropdownToOne: "Process field update"
    
    alt User wants to create new record
        User->>SingleRecordPicker: "Click create new option"
        SingleRecordPicker->>RecordDetailRelationSectionDropdownToOne: "Call handleCreateNew"
        RecordDetailRelationSectionDropdownToOne->>useAddNewRecordAndOpenRightDrawer: "Create and open new record"
        useAddNewRecordAndOpenRightDrawer-->>User: "Open right drawer with new record form"
    end
Loading

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

Copy link
Member

@Weiko Weiko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

return;

onSubmit?.({ newValue: selectedMorphItem.recordId });
onSubmit?.({ newValue: { id: selectedMorphItem.recordId } });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it not possible to have it strongly typed?

@charlesBochet charlesBochet merged commit 8914ba9 into main Oct 8, 2025
52 checks passed
@charlesBochet charlesBochet deleted the critical-bug-fixes branch October 8, 2025 09:30
Copy link
Contributor

github-actions bot commented Oct 8, 2025

🚀 Preview Environment Ready!

Your preview environment is available at: http://bore.pub:52952

This environment will automatically shut down when the PR is closed or after 5 hours.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants