Skip to content

Commit de57de8

Browse files
authored
revert strict enforcement of "required" and "min" for relationships. See changelog for rationale. I made this mess, I am reverting it heh (#5039)
1 parent 6067831 commit de57de8

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
* The `?render-areas=1` API feature now correctly disregards areas in separate documents loaded via relationship fields. Formerly their presence resulted in an error, not a rendering.
1616
* Make conditional fields work in Image Editor.
1717

18+
### Changes
19+
20+
* Rolled back a change in 4.16.0 that strictly enforced `required` and `min` for relationship fields. Because the related document can be archived or deleted at any time, it is misleading to offer such enforcement. Also, it greatly complicates adding these constraints to existing schemas, resulting in surprising and unwanted behaviors. Therefore it is better for these constraints to be soft constraints on the front end. `max` is still a hard constraint.
21+
1822
## 4.20.0 (2025-08-06)
1923

2024
### Adds

modules/@apostrophecms/schema/lib/addFieldTypes.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,12 +1183,9 @@ module.exports = (self) => {
11831183
}
11841184
destination[field.name] = actualDocs;
11851185
}
1186-
if (field.required && (destination[field.name].length === 0)) {
1187-
throw self.apos.error('required');
1188-
}
1189-
if (field.min && field.min > destination[field.name].length) {
1190-
throw self.apos.error('min', `Minimum ${field.withType} required not reached.`);
1191-
}
1186+
// "min" and "required" are not enforced server-side for relationships because it is always possible
1187+
// for the related document to be removed independently at some point. This leads to too many
1188+
// edge cases and knock-on effects if enforced
11921189
if (field.max && field.max < destination[field.name].length) {
11931190
throw self.apos.error('max', `Maximum ${field.withType} required reached.`);
11941191
}

0 commit comments

Comments
 (0)