Skip to content

Commit b49a264

Browse files
docs(skills): teach transferBehavior, the Change Owner cascade, in the data skill (#37076)
repo:objectstack#4 · os-justin · session_01QSeKYo86w1wqy2z2fMrryr Fixes #36713 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:AI 助手在建数据模型时,知道可以让「更换负责人」连带移交子记录,并知道哪些写法会被拒绝;此前它不知道有这个设置。 - 为什么做:属于「技能包教学」这条线,是「更换负责人连带移交」功能落地后欠下的教学补齐。 - 出错会怎样:AI 可能照着教学写出系统拒收的设置,保存时当场报错;可以直接撤回,只是文字改动。 - 要你做什么:批准合并。只改技能文字和一道评测题;按需人工批准处理,是因为契约审核判它「涉及权限」:教的是「更换负责人」连带移交子记录,负责人决定谁能看到记录。它没有放宽任何检查,也没有教授权写法。契约审核 PASS:记录 7141869539,Head-sha `84459523cd70acc86a20162638981d7e2a1a6473`。 ## What changes - `skills/objectstack-data/rules/relationships.md`, Delete Behaviors: one paragraph teaches `transferBehavior: 'cascade'` on a child's `lookup` / `master_detail`. It says what the parent's Change Owner dialog then offers (moving the child rows the parent's previous owner owns), that the default is `'none'`, when to declare it, and the parse refusals in one sentence. - `skills/objectstack-data/rules/field-types.md`: `transferBehavior` is listed in the Key Config cell of the `lookup` and `master_detail` rows. - `skills/objectstack-data/evals/objects-fields-relationships.json`: one case (id 28) that asks for the declaration in place of an owner-rewriting hook, and where it is refused. - One `@objectstack/skills` patch changeset. The refusals taught are the ones the merged code makes (read on main at 896bfc4, `packages/spec/src/data/field.zod.ts`, `object.zod.ts` and `user-action-transfer.ts`): the key on any type but `lookup` / `master_detail` (an authored `'none'` too); `'cascade'` on a reference to a `sys_` object; `'cascade'` with `multiple: true`; `'cascade'` on a field of an object that does not offer Change Owner itself (not structurally eligible, a `controlled_by_parent` detail, or `userActions.transfer` off). ### Paid for in the same files (no ceiling row moved, the ratchet script is not edited) - relationships.md: the two "Incorrect" code blocks become one sentence each (each block restated the pattern above it); two `required: false` lines the Relationship Types table already states as the default; two code comments that repeated the `name:` under them; and three prose repeats in the inline-edit part. - field-types.md: the autonumber example in the Calculated row, which the Autonumber section gives; "embedded" twice in the Embedded table, which its heading and lead sentence already say. | File | Lines before / after | Tokens before / after | Ceiling | Headroom | |:--|:--|:--|:--|:--| | `rules/relationships.md` | 401 / 389 | 4202 / 4201 | 4203 | 2 | | `rules/field-types.md` | 270 / 270 | 3540 / 3539 | 3541 | 2 | | `evals/objects-fields-relationships.json` | 491 / 506 | 8588 / 8922 | not ratcheted | n/a | | whole `skills/objectstack-data` bundle | 4715 / 4718 | 62592 / 62923 (bytes 250366 / 251692) | n/a | n/a | Net lines in `skills/**`: +3 (budget +10). Without the eval fixture the bundle shrinks: 3779 / 3767 lines, 175356 / 175348 bytes. ## Tests No package source changes, so there is no package test to run. The gates that read these files, at 8445952: - `node scripts/check-skills-token-ratchet.mjs`: exit 0, `60 authored bundle file(s) within their ceilings`. - `pnpm --filter @objectstack/spec run check:skill-served-sections`: exit 0, 24 served sections (the Roll-up Summaries section this file serves is untouched). - `node ui/scripts/check-skill-eval-tokens.mjs`: exit 0, `Every must_contain token is taught by its own skill bundle.` - `pnpm check:skill-links`, `check:skill-identifier-liveness`, `check:skill-compatibility`, `check:skill-frame-sync`, `check:doc-authoring`, `check:nul-bytes`: exit 0. ## Acceptance notes - `evals/README.md` lists what the fixture covers and does not name the new case; it is outside this card's file surface. - Open PR #36158 raises both ceilings and, merged with today's main alone, already reads 4347 tokens against its own 4343 row for relationships.md. Merged with this branch it reads 4346. That gap is not from this change, which removes 4 bytes. - Combined with open PR #37072 (head cd69066): relationships.md 16798 bytes, 4200 tokens, ceiling 4203; field-types.md 14156 bytes, 3539 tokens, ceiling 3541. ## Verification Read first, by risk: 1. `skills/objectstack-data/rules/relationships.md`, the new paragraph before "Roll-up Summaries": every refusal named there against the merged schema. 2. The same file, "Incorrect vs Correct": two code blocks reduced to a sentence each. 3. `skills/objectstack-data/rules/field-types.md`, the Relational table rows. Two-minute check: `node scripts/check-skills-token-ratchet.mjs` exits 0 and prints headroom 2 for both rule files. <details> <summary>Gate readings at 8445952</summary> - `node scripts/pm/dispatch-gates.mjs --ran`: `✓ dispatch-gates --ran: 48 derived famil(ies) accounted for — 43 run, 5 NOT-MEASURED (5 DERIVED from a recorded exit 3).` - NOT MEASURED locally (exit 3, PREREQUISITE NOT MET: no built `dist/` in this worktree; none reads a file this diff changes; CI runs them): `check:doc-formula-expressions`, `check:dts-closure`, `check:dual-build-cjs-loads`, `check:lean-entry-closure`, `check:sourcemap-no-sources-content`. - `node scripts/pm/overlap-check.mjs`: `VERDICT clean exit 0` against origin/main, #37072 and #36158. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01QSeKYo86w1wqy2z2fMrryr)_ <!-- signed: repo:objectstack#4 · os-justin · session_01QSeKYpEsWWE9Y5YtSsDgqZ --> Co-authored-by: Claude <noreply@anthropic.com>
1 parent adb3aef commit b49a264

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)
@@ -379,24 +382,9 @@ surfaces a "children" list.
379382

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

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

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

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

0 commit comments

Comments
 (0)