@@ -336,6 +336,19 @@ const CBP_ORPHAN_CONSEQUENCE =
336336 * 2. `required: true` + `readonly: true`;
337337 * 3. `required: true` + `system: true`.
338338 *
339+ * ⚠️ Amended by ruling A of #30905 (ADR-0055 §1 as amended): the object's
340+ * ONLY `master_detail`, declared `required: false`, is its optional master — a
341+ * detail row may name none, and such a row is read by its owner and by View
342+ * All on the detail — so that spelling passes, and only `readonly` / `system`
343+ * on it is reported (the parse refuses it too, shape `master-not-writable`).
344+ * Shape 1 now reads: `required` absent (or not a boolean) on any
345+ * `master_detail`, or `false` on one beside another `master_detail`. On the
346+ * sole `master_detail` an absent `required` is reported with both honest
347+ * spellings, because the parse cannot see the omission (it reads the parsed
348+ * `false`, so it admits the optional master) while `ObjectSchema.create()`
349+ * forces it to `true`: one source, two meanings, until the author writes one.
350+ * The fix stays `required: true`, the reading the builder already gives it.
351+ *
339352 * Why these three. A `controlled_by_parent` detail derives ALL of its record
340353 * access from the master its `master_detail` reference names (ADR-0055: such an
341354 * object "must declare exactly one required `master_detail` field"). Record
@@ -394,21 +407,37 @@ function cbpMasterReferenceFinding(
394407 fieldPath : string ,
395408 parent : string ,
396409 def : any ,
410+ masterDetailCount : number ,
397411) : LintIssue | undefined {
398- const missingRequired = def . required !== true ;
412+ // [ADR-0055 §1 as amended · #30905 ruling A] The object's ONLY
413+ // `master_detail`, declared `required: false`, is its optional master — the
414+ // spelling passes. Beside another `master_detail` an explicit `false` is
415+ // judged as before; an omitted `required` is reported on every field.
416+ const soleMasterDetail = masterDetailCount === 1 ;
417+ const optionalMaster = soleMasterDetail && def . required === false ;
418+ const missingRequired = def . required !== true && ! optionalMaster ;
419+ // On the sole `master_detail`, an omitted (or non-boolean) `required` has
420+ // two honest spellings; elsewhere only `required: true` is one.
421+ const eitherSpelling = missingRequired && soleMasterDetail ;
399422 const flags = ( [ 'readonly' , 'system' ] as const ) . filter ( ( flag ) => def [ flag ] === true ) ;
400423 if ( ! missingRequired && flags . length === 0 ) return undefined ;
401424
402425 const subject = `master_detail "${ objectName } .${ fieldName } " → ${ parent } ` ;
426+ const requirement = eitherSpelling
427+ ? 'must declare required: true (or required: false for an optional master)'
428+ : 'must be required' ;
403429 // [#22161] One verdict per shape, ending in the one shared consequence; the
404430 // derivation (why the record is unreadable, why the flags skip the check)
405431 // is `os explain` text.
406432 const message = missingRequired
407433 ? flags . length === 0
408- ? `${ subject } must be required: ${ CBP_ORPHAN_CONSEQUENCE } `
409- : `${ subject } must be required and not marked ${ flags . join ( ' or ' ) } : ${ CBP_ORPHAN_CONSEQUENCE } `
410- : `${ subject } is marked ${ flags . join ( ' and ' ) } , which skips its required check: ` +
411- CBP_ORPHAN_CONSEQUENCE ;
434+ ? `${ subject } ${ requirement } : ${ CBP_ORPHAN_CONSEQUENCE } `
435+ : `${ subject } ${ requirement } and not be marked ${ flags . join ( ' or ' ) } : ${ CBP_ORPHAN_CONSEQUENCE } `
436+ : optionalMaster
437+ ? `${ subject } is the optional master and is marked ${ flags . join ( ' and ' ) } , which no detail ` +
438+ 'write supplies: the master reference must be writable'
439+ : `${ subject } is marked ${ flags . join ( ' and ' ) } , which skips its required check: ` +
440+ CBP_ORPHAN_CONSEQUENCE ;
412441
413442 return {
414443 severity : 'error' ,
@@ -1016,7 +1045,10 @@ export function lintDataModel(objects: any[]): LintIssue[] {
10161045 // `master_detail` is a likely-wrong choice and stays a `warning`,
10171046 // byte-for-byte as before.
10181047 if ( obj . sharingModel === 'controlled_by_parent' ) {
1019- const finding = cbpMasterReferenceFinding ( obj . name , fieldName , fieldPath , parent , def ) ;
1048+ const masterDetailCount = fields . filter ( ( { def : f } ) => f ?. type === 'master_detail' ) . length ;
1049+ const finding = cbpMasterReferenceFinding (
1050+ obj . name , fieldName , fieldPath , parent , def , masterDetailCount ,
1051+ ) ;
10201052 if ( finding ) issues . push ( finding ) ;
10211053 } else if ( def . required !== true ) {
10221054 issues . push ( {
0 commit comments