diff --git a/.changeset/36713-skills-transfer-behavior.md b/.changeset/36713-skills-transfer-behavior.md new file mode 100644 index 00000000000..bca08b2a97d --- /dev/null +++ b/.changeset/36713-skills-transfer-behavior.md @@ -0,0 +1,10 @@ +--- +'@objectstack/skills': patch +--- + +docs(skills): the data skill teaches `transferBehavior`, the Change Owner cascade of a relationship + +Clause-②: no +Metadata-protocol: none + +objectstack-data's `rules/relationships.md`, Delete Behaviors: one paragraph says what `transferBehavior: 'cascade'` on a child's `lookup` / `master_detail` does (the parent's Change Owner dialog offers to move the child rows its previous owner owns too), when to declare it, that the default is `'none'`, and where parse refuses it: the key on any other type, and `cascade` on a `sys_*` reference, on `multiple: true`, and on a child that does not offer Change Owner itself, such as a `controlled_by_parent` detail. `rules/field-types.md` lists the key on the `lookup` and `master_detail` rows. `evals/objects-fields-relationships.json` gains one case. The new text is paid for by removing restatement in the same files: in relationships.md the two "Incorrect" code blocks become one sentence each, and two `required: false` lines and five comment or prose repeats go; in field-types.md the autonumber example that the Autonumber section already gives and two "embedded" repeats go. diff --git a/skills/objectstack-data/evals/objects-fields-relationships.json b/skills/objectstack-data/evals/objects-fields-relationships.json index 7ae2edb5bc4..a883818441a 100644 --- a/skills/objectstack-data/evals/objects-fields-relationships.json +++ b/skills/objectstack-data/evals/objects-fields-relationships.json @@ -486,6 +486,21 @@ "overrides:" ] } + }, + { + "id": 28, + "prompt": "When a sales manager changes the owner of an `account`, the Change Owner dialog should offer to hand the account's `opportunity` records that the old owner owns to the new owner too. `opportunity.account` is a `lookup` to `account`. A colleague proposes a hook on `account` that rewrites `owner_id` on its opportunities. What do we declare instead, and where is that declaration refused?", + "expected_output": "No hook: declare the cascade on the child's reference field, beside `deleteBehavior`: on `opportunity`, `account: { type: 'lookup', reference: 'account', transferBehavior: 'cascade' }`. The account's Change Owner dialog then offers that relationship, and moves the opportunities the account's previous owner owns; the default `'none'` leaves them with their owner. The key is refused at parse on any type but `lookup` / `master_detail`; `cascade` is also refused on a reference to a `sys_*` object, on a `multiple: true` field, and on a child object that does not offer Change Owner itself, such as a `controlled_by_parent` detail.", + "files": [], + "assertions": { + "must_contain": [ + "transferBehavior: 'cascade'", + "controlled_by_parent" + ], + "must_not_contain": [ + "deleteBehavior: 'cascade'" + ] + } } ] } diff --git a/skills/objectstack-data/rules/field-types.md b/skills/objectstack-data/rules/field-types.md index 252cb4e702a..9a8afe32aef 100644 --- a/skills/objectstack-data/rules/field-types.md +++ b/skills/objectstack-data/rules/field-types.md @@ -89,8 +89,8 @@ options: [ | Type | When to Use | Key Config | |:-----|:------------|:-----------| -| `lookup` | Reference another object (independent) | `reference`, `lookupFilters`, `multiple`, `deleteBehavior`, `lookupAutofill` | -| `master_detail` | Parent–child with lifecycle control | `reference`, `deleteBehavior` (`cascade`/`restrict` — `set_null` is refused), `lookupAutofill` | +| `lookup` | Reference another object (independent) | `reference`, `lookupFilters`, `multiple`, `deleteBehavior`, `transferBehavior`, `lookupAutofill` | +| `master_detail` | Parent–child with lifecycle control | `reference`, `deleteBehavior` (`cascade`/`restrict` — `set_null` is refused), `transferBehavior`, `lookupAutofill` | | `tree` | Hierarchical self-reference | `reference` — optional; when written, this object's own name (any other object is refused at parse) | | `user` | Person picker — a lookup specialized to `sys_user` (reviewer, watchers). Stored identically to `lookup` | `multiple` (collaborators), `defaultValue: 'current_user'`, `deleteBehavior` (no default; declared, as on `lookup`: relationships.md → Delete Behaviors) | @@ -122,8 +122,8 @@ Stored as JSON on the parent row, no separate table/FK: | Type | When to Use | |:-----|:------------| -| `composite` | Single embedded JSON object, **untyped**: a field declares no sub-fields (`fields`/`subFields` are refused) | -| `repeater` | Embedded JSON **array**, **untyped**: no sub-fields or `columns`; a typed list is a `master_detail` child a parent `fieldGroups[].relatedList` names | +| `composite` | Single JSON object, **untyped**: a field declares no sub-fields (`fields`/`subFields` are refused) | +| `repeater` | JSON **array**, **untyped**: no sub-fields or `columns`; a typed list is a `master_detail` child a parent `fieldGroups[].relatedList` names | | `record` | Name-keyed **map** of embedded sub-objects (insertion order = display order; ADR-0007) | ## Calculated @@ -132,7 +132,7 @@ Stored as JSON on the parent row, no separate table/FK: |:-----|:------------|:-------| | `formula` | Computed on read: neither aggregatable nor a dataset or cube dimension (group key); both need a stored field of its return type with the same `expression` (objectstack-ui → Dashboards → Dataset-Bound Widgets) that reads only its own row (relationships.md → Computed column) | `expression` (CEL, `record.` prefixes), `returnType` (`'number' \| 'text' \| 'boolean' \| 'date' \| 'currency'`); `'currency'` carries its own `currencyConfig` | | `summary` | Roll-up aggregation from child records | `summaryOperations` ({ object, field? (omit for `count`), function, relationshipField?, filter? }) | -| `autonumber` | Auto-incrementing display format (→ Autonumber) | `format` (shorthand) / `autonumberFormat` (canonical) — e.g., `"CASE-{0000}"` | +| `autonumber` | Auto-incrementing display format (→ Autonumber) | `format` (shorthand) / `autonumberFormat` (canonical) | ## Enhanced Types diff --git a/skills/objectstack-data/rules/relationships.md b/skills/objectstack-data/rules/relationships.md index 43fff87fbf7..00ee1ca5b35 100644 --- a/skills/objectstack-data/rules/relationships.md +++ b/skills/objectstack-data/rules/relationships.md @@ -27,7 +27,6 @@ export default ObjectSchema.create({ account_id: { type: 'lookup', reference: 'account', - required: false, }, } }); @@ -36,7 +35,7 @@ export default ObjectSchema.create({ ### One-to-Many: master_detail ```typescript -// Parent: Invoice +// Parent export default ObjectSchema.create({ name: 'invoice', sharingModel: 'public_read_write', @@ -53,7 +52,7 @@ export default ObjectSchema.create({ } }); -// Child: Line Item (owned by parent) +// Child export default ObjectSchema.create({ name: 'invoice_line_item', sharingModel: 'controlled_by_parent', @@ -154,7 +153,6 @@ export default ObjectSchema.create({ parent_category: { type: 'tree', reference: 'category', - required: false, }, } }); @@ -178,6 +176,12 @@ field keeps the deleted user's id. `restrict`, and `set_null` on a `required` field (a `multiple` one only when the removal would empty it), refuse the delete with `409 DELETE_RESTRICTED`. +**Change Owner:** `transferBehavior: 'cascade'` (default `'none'`) on a child's `lookup` / +`master_detail` has the parent's Change Owner dialog offer to move the child rows its +previous owner owns too; declare it where children follow the parent's owner. Parse +refuses the key on other types, and `cascade` on a `sys_*` reference, `multiple: true`, +or a child not offering Change Owner itself (a `controlled_by_parent` detail). + ## Roll-up Summaries A parent `summary` field aggregates a child collection. The engine recomputes it @@ -253,9 +257,8 @@ field group of the parent names that child** (`relatedList`): the group draws the child's table at its place in the record's details and in the parent's entry form (below the form's fields when its sections name no field group), and parent + children save in **one atomic transaction**. Without the group -nothing changes: the child is a tab and the form has no lines, whatever -`inlineEdit` says. A parent or child declaring `enable.apiMethods` must list -`'bulk'`, or that save is refused `405 OBJECT_API_METHOD_NOT_ALLOWED`. +nothing changes: the child is a tab and the form has no lines. A parent or child +declaring `enable.apiMethods` must list `'bulk'`, or that save is refused `405 OBJECT_API_METHOD_NOT_ALLOWED`. ```typescript // PARENT `invoice`: the group places the lines and holds no fields @@ -282,17 +285,17 @@ The rendering side: objectstack-ui → Master-Detail Forms. `inlineEdit` only picks how a placed child's rows are entered: ```typescript -inlineEdit: true // auto — pick grid/form from the child's shape (default) +inlineEdit: true // auto (default) inlineEdit: 'grid' // editable line-item grid (fast bulk entry; thin children) inlineEdit: 'form' // read-only list; "Add" / per-row edit opens the FULL form ``` **`true`** / omitted — **smart default**: picks `form` when the child has rich/form-only fields (textarea, file, image, json, location…) or more than ~8 -editable fields, else `grid`. Set the string to override. +editable fields, else `grid`. **Modeling a `'grid'` line item for the full editor.** The grid lights up extra -behaviors purely from how you model the child + parent: +behaviors from how you model the child + parent: ```typescript // Parent (a field group names invoice_line, as above) @@ -378,24 +381,9 @@ references the parent through several FKs (e.g. `primary_account` + ### ❌ Incorrect — Using lookup When master_detail is Needed -```typescript -export default ObjectSchema.create({ - name: 'invoice_line_item', - fields: { - invoice_id: { - type: 'lookup', // ❌ Child can exist without parent — use the master_detail pattern above - reference: 'invoice', - }, - } -}); -``` +A line item on a `lookup` can exist without its parent: use `master_detail`. ### ❌ Incorrect — Native Many-to-Many -```typescript -{ - type: 'many_to_many', // ❌ Not a valid field type — use a junction object - reference: 'tag', -} -``` +No `many_to_many` field type exists: use a junction object.