core icon indicating copy to clipboard operation
core copied to clipboard

Relationship Field: Relate option remains active ignoring cardinality constraints

Open oidacra opened this issue 1 year ago • 5 comments

Problem Statement

The Relationship Field's "Relate" option remains active regardless of cardinality constraints. When one side of the relationship has "One" cardinality and already has related content, the relate option should be inactive until the existing relationship is removed. This affects content editors who may attempt to create invalid relationships that violate cardinality rules.

Steps to Reproduce

  1. Create a content type with a Relationship Field
  2. Set cardinality to "One to Many" or "One to One" on one side
  3. Create content and establish a relationship that satisfies the "One" side constraint
  4. Attempt to create another relationship from the same "One" side
  5. Notice that the "Relate" option remains active when it should be disabled

Acceptance Criteria

  • [ ] When a relationship field has "One" cardinality on one side and already has related content, the "Relate" option should be disabled
  • [ ] The "Relate" option should become active again when the existing relationship is removed
  • [ ] The UI should provide clear visual feedback about why the relate option is disabled
  • [ ] This behavior should work consistently across all relationship field configurations with "One" cardinality
  • [ ] For 1:1 cardinality: When an item is already selected, the "Add more" (+) button must be disabled to prevent selecting additional items. It should re-enable only when the existing item is removed

dotCMS Version

Latest

Proposed Objective

Core Features

Proposed Priority

Priority 2 - Important

External Links... Slack Conversations, Support Tickets, Figma Designs, etc.

Assumptions & Initiation Needs

  • Existing relationship field functionality should remain unchanged for other cardinality types
  • This fix should not affect existing relationships

Quality Assurance Notes & Workarounds

  • Test with different cardinality configurations (One-to-One, One-to-Many)
  • Verify that the UI correctly reflects the disabled state
  • Ensure that removing relationships re-enables the relate option
  • For 1:1: Verify that after selecting one item, the "Add more" button is disabled and cannot be clicked

Sub-Tasks & Estimates

  • [ ] Investigate current relationship field logic (2 points)
  • [ ] Implement cardinality validation for relate option (3 points)
  • [ ] Update UI to disable/enable relate option based on cardinality (2 points)
  • [ ] Disable "Add more" button for 1:1 cardinality when an item is already selected (2 points)
  • [ ] Add unit tests for cardinality validation (2 points)
  • [ ] Update integration tests (1 point)

oidacra avatar Jul 24 '25 14:07 oidacra

slack thread https://dotcms.slack.com/archives/C0893BF7GRJ/p1743626020693709

erickgonzalez avatar Aug 12 '25 20:08 erickgonzalez

In the relationship field, when a user selects content that violates the relationship constraints, the error currently appears after the user clicks the Save button. Instead, the error should be shown directly in the field context with a message such as ‘The content is already related to another item,’ or the item should appear in a disabled state to preventt the error.

Image

nicobytes avatar Aug 13 '25 14:08 nicobytes

Test plan generated and reviewed:

32792-35134-test-plan.md

erickgonzalez avatar Mar 31 '26 17:03 erickgonzalez

QA PASSED ✅

adrianjm-dotCMS avatar Apr 10 '26 13:04 adrianjm-dotCMS