Skip to content

Commit 8445952

Browse files
committed
docs(skills): teach transferBehavior, the Change Owner cascade, in the data skill
Claude-Session: https://claude.ai/code/session_01QSeKYo86w1wqy2z2fMrryr Co-authored-by: Claude <noreply@anthropic.com>
1 parent 896bfc4 commit 8445952

4 files changed

Lines changed: 45 additions & 32 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/skills': patch
3+
---
4+
5+
docs(skills): the data skill teaches `transferBehavior`, the Change Owner cascade of a relationship
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
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.

‎skills/objectstack-data/evals/objects-fields-relationships.json‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,21 @@
486486
"overrides:"
487487
]
488488
}
489+
},
490+
{
491+
"id": 28,
492+
"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?",
493+
"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.",
494+
"files": [],
495+
"assertions": {
496+
"must_contain": [
497+
"transferBehavior: 'cascade'",
498+
"controlled_by_parent"
499+
],
500+
"must_not_contain": [
501+
"deleteBehavior: 'cascade'"
502+
]
503+
}
489504
}
490505
]
491506
}

‎skills/objectstack-data/rules/field-types.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ options: [
8989

9090
| Type | When to Use | Key Config |
9191
|:-----|:------------|:-----------|
92-
| `lookup` | Reference another object (independent) | `reference`, `lookupFilters`, `multiple`, `deleteBehavior`, `lookupAutofill` |
93-
| `master_detail` | Parent–child with lifecycle control | `reference`, `deleteBehavior` (`cascade`/`restrict` — `set_null` is refused), `lookupAutofill` |
92+
| `lookup` | Reference another object (independent) | `reference`, `lookupFilters`, `multiple`, `deleteBehavior`, `transferBehavior`, `lookupAutofill` |
93+
| `master_detail` | Parent–child with lifecycle control | `reference`, `deleteBehavior` (`cascade`/`restrict` — `set_null` is refused), `transferBehavior`, `lookupAutofill` |
9494
| `tree` | Hierarchical self-reference | `reference` — optional; when written, this object's own name (any other object is refused at parse) |
9595
| `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) |
9696

@@ -122,8 +122,8 @@ Stored as JSON on the parent row, no separate table/FK:
122122

123123
| Type | When to Use |
124124
|:-----|:------------|
125-
| `composite` | Single embedded JSON object, **untyped**: a field declares no sub-fields (`fields`/`subFields` are refused) |
126-
| `repeater` | Embedded JSON **array**, **untyped**: no sub-fields or `columns`; a typed list is a `master_detail` child a parent `fieldGroups[].relatedList` names |
125+
| `composite` | Single JSON object, **untyped**: a field declares no sub-fields (`fields`/`subFields` are refused) |
126+
| `repeater` | JSON **array**, **untyped**: no sub-fields or `columns`; a typed list is a `master_detail` child a parent `fieldGroups[].relatedList` names |
127127
| `record` | Name-keyed **map** of embedded sub-objects (insertion order = display order; ADR-0007) |
128128

129129
## Calculated
@@ -132,7 +132,7 @@ Stored as JSON on the parent row, no separate table/FK:
132132
|:-----|:------------|:-------|
133133
| `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` |
134134
| `summary` | Roll-up aggregation from child records | `summaryOperations` ({ object, field? (omit for `count`), function, relationshipField?, filter? }) |
135-
| `autonumber` | Auto-incrementing display format (→ Autonumber) | `format` (shorthand) / `autonumberFormat` (canonical) — e.g., `"CASE-{0000}"` |
135+
| `autonumber` | Auto-incrementing display format (→ Autonumber) | `format` (shorthand) / `autonumberFormat` (canonical) |
136136

137137
## Enhanced Types
138138

‎skills/objectstack-data/rules/relationships.md‎

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export default ObjectSchema.create({
2727
account_id: {
2828
type: 'lookup',
2929
reference: 'account',
30-
required: false,
3130
},
3231
}
3332
});
@@ -36,7 +35,7 @@ export default ObjectSchema.create({
3635
### One-to-Many: master_detail
3736

3837
```typescript
39-
// Parent: Invoice
38+
// Parent
4039
export default ObjectSchema.create({
4140
name: 'invoice',
4241
sharingModel: 'public_read_write',
@@ -53,7 +52,7 @@ export default ObjectSchema.create({
5352
}
5453
});
5554

56-
// Child: Line Item (owned by parent)
55+
// Child
5756
export default ObjectSchema.create({
5857
name: 'invoice_line_item',
5958
sharingModel: 'controlled_by_parent',
@@ -154,7 +153,6 @@ export default ObjectSchema.create({
154153
parent_category: {
155154
type: 'tree',
156155
reference: 'category',
157-
required: false,
158156
},
159157
}
160158
});
@@ -178,6 +176,12 @@ field keeps the deleted user's id. `restrict`, and `set_null` on a `required`
178176
field (a `multiple` one only when the removal would empty it), refuse the delete
179177
with `409 DELETE_RESTRICTED`.
180178

179+
**Change Owner:** `transferBehavior: 'cascade'` (default `'none'`) on a child's `lookup` /
180+
`master_detail` has the parent's Change Owner dialog offer to move the child rows its
181+
previous owner owns too; declare it where children follow the parent's owner. Parse
182+
refuses the key on other types, and `cascade` on a `sys_*` reference, `multiple: true`,
183+
or a child not offering Change Owner itself (a `controlled_by_parent` detail).
184+
181185
## Roll-up Summaries
182186

183187
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
253257
the child's table at its place in the record's details and in the parent's
254258
entry form (below the form's fields when its sections name no field group),
255259
and parent + children save in **one atomic transaction**. Without the group
256-
nothing changes: the child is a tab and the form has no lines, whatever
257-
`inlineEdit` says. A parent or child declaring `enable.apiMethods` must list
258-
`'bulk'`, or that save is refused `405 OBJECT_API_METHOD_NOT_ALLOWED`.
260+
nothing changes: the child is a tab and the form has no lines. A parent or child
261+
declaring `enable.apiMethods` must list `'bulk'`, or that save is refused `405 OBJECT_API_METHOD_NOT_ALLOWED`.
259262

260263
```typescript
261264
// PARENT `invoice`: the group places the lines and holds no fields
@@ -282,17 +285,17 @@ The rendering side: objectstack-ui → Master-Detail Forms.
282285
`inlineEdit` only picks how a placed child's rows are entered:
283286

284287
```typescript
285-
inlineEdit: true // auto — pick grid/form from the child's shape (default)
288+
inlineEdit: true // auto (default)
286289
inlineEdit: 'grid' // editable line-item grid (fast bulk entry; thin children)
287290
inlineEdit: 'form' // read-only list; "Add" / per-row edit opens the FULL form
288291
```
289292

290293
**`true`** / omitted — **smart default**: picks `form` when the child has
291294
rich/form-only fields (textarea, file, image, json, location…) or more than ~8
292-
editable fields, else `grid`. Set the string to override.
295+
editable fields, else `grid`.
293296

294297
**Modeling a `'grid'` line item for the full editor.** The grid lights up extra
295-
behaviors purely from how you model the child + parent:
298+
behaviors from how you model the child + parent:
296299

297300
```typescript
298301
// Parent (a field group names invoice_line, as above)
@@ -378,24 +381,9 @@ references the parent through several FKs (e.g. `primary_account` +
378381

379382
### ❌ Incorrect — Using lookup When master_detail is Needed
380383

381-
```typescript
382-
export default ObjectSchema.create({
383-
name: 'invoice_line_item',
384-
fields: {
385-
invoice_id: {
386-
type: 'lookup', // ❌ Child can exist without parent — use the master_detail pattern above
387-
reference: 'invoice',
388-
},
389-
}
390-
});
391-
```
384+
A line item on a `lookup` can exist without its parent: use `master_detail`.
392385

393386
### ❌ Incorrect — Native Many-to-Many
394387

395-
```typescript
396-
{
397-
type: 'many_to_many', // ❌ Not a valid field type — use a junction object
398-
reference: 'tag',
399-
}
400-
```
388+
No `many_to_many` field type exists: use a junction object.
401389

0 commit comments

Comments
 (0)