Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/36224-inline-edit-form-group.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@objectstack/skills': patch
---

docs(skills): entering line items in the parent's form is taught as a parent field group naming the child, not `inlineEdit` alone

Clause-②: no
Metadata-protocol: none

objectstack-data's `rules/relationships.md` (Inline Editing), objectstack-ui's `rules/list-views.md` (Master-Detail Forms) and the objectstack-ui `SKILL.md` trap list taught that `inlineEdit: true` on the child's `master_detail` field puts the child grid into the parent's form. They now teach the rule the platform applies: the parent's form enters a child's rows where a field group of the parent names that child (`fieldGroups: [{ key: 'lines', label: 'Lines', relatedList: 'invoice_line' }]`), `inlineEdit` only picks how those rows are edited, and without the group the child is a tab and the form has no lines. Text only; each file's old wording is cut to pay for the new. Two eval cases that expected the old answer are corrected and objectstack-data gains one case for form entry of quote lines.
18 changes: 16 additions & 2 deletions skills/objectstack-data/evals/objects-fields-relationships.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@
{
"id": 2,
"prompt": "Model invoices with line items, and let invoices be tagged with many tags where each tagging records who added it and when. A rep who owns a line item but can only read the invoice may still correct that line.",
"expected_output": "Line items: `invoice_line` with a `master_detail` field to `invoice`, `required: true`, `deleteBehavior: 'cascade'` (or `'restrict'` — `set_null` is refused on master_detail), `inlineEdit` on that relationship, and a `summary` roll-up field on the parent. Tagging carries attributes, so it is a junction object (`invoice_tag`) with two `lookup` fields plus `added_by` / `added_at` — not a `multiple: true` lookup (an array of ids) and not a `many_to_many` type, which does not exist. The line object is `sharingModel: 'controlled_by_parent'` with `sharing: { controlledByParent: { ownerMayEdit: true } }` (by-id update only; every other write still needs master edit). `added_by` is `type: 'user'` — never a `lookup` to a `user` object, which does not exist.",
"expected_output": "Line items: `invoice_line` with a `master_detail` field to `invoice`, `required: true`, `deleteBehavior: 'cascade'` (or `'restrict'` — `set_null` is refused on master_detail), and a `summary` roll-up field on the parent. Tagging carries attributes, so it is a junction object (`invoice_tag`) with two `lookup` fields plus `added_by` / `added_at` — not a `multiple: true` lookup (an array of ids) and not a `many_to_many` type, which does not exist. The line object is `sharingModel: 'controlled_by_parent'` with `sharing: { controlledByParent: { ownerMayEdit: true } }` (by-id update only; every other write still needs master edit). `added_by` is `type: 'user'` — never a `lookup` to a `user` object, which does not exist.",
"files": [],
"assertions": {
"must_contain": [
"master_detail",
"deleteBehavior",
"inlineEdit",
"summary",
"lookup",
"ownerMayEdit",
Expand Down Expand Up @@ -432,6 +431,21 @@
"event: 'afterInsert'"
]
}
},
{
"id": 25,
"prompt": "`quote_line` 通过 `master_detail` 字段 `quote` 归属 `quote`。新建报价单时要在表单里直接录明细,和报价单一起保存。该怎么声明?",
"expected_output": "On the PARENT `quote` object, a field group that names the child: `fieldGroups: [..., { key: 'lines', label: '明细', relatedList: 'quote_line' }]` (such a group holds no fields). The standard create/edit form of `quote` then enters the lines at that group and saves quote + lines in one atomic transaction, and the record page draws the same table there. Without the group nothing changes: `quote_line` is a tab and the form has no lines, whatever `inlineEdit` on `quote_line.quote` says; `inlineEdit` only picks how the rows are edited (`'grid'` / `'form'`, `true` or absent picks by the child's shape). No custom page and no form view is needed. If either object declares `enable.apiMethods`, it must list `'bulk'`.",
"files": [],
"assertions": {
"must_contain": [
"fieldGroups",
"relatedList: 'quote_line'"
],
"must_not_contain": [
"definePage"
]
}
}
]
}
52 changes: 23 additions & 29 deletions skills/objectstack-data/rules/relationships.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,44 +247,38 @@ which clients are meant to see, acknowledged — a note:

## Inline Editing (Master-Detail Entry)

Declare inline editing **on the relationship**, in the data model — not in a form
view. Set `inlineEdit: true` on the child's `master_detail` (or `lookup`) field
that points back to the parent. The parent's **standard** create/edit form then
renders an editable grid for these children and saves parent + children in **one
atomic transaction**. A parent or child declaring `enable.apiMethods` must list
The parent's standard create/edit form enters a child's rows where **a
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`.

```typescript
// On the CHILD object's FK field:
export default ObjectSchema.create({
name: 'invoice_line',
sharingModel: 'controlled_by_parent',
fields: {
invoice: {
type: 'master_detail',
reference: 'invoice',
inlineEdit: true, // ← edited inline within the Invoice form
inlineTitle: 'Line Items', // optional grid title
// inlineColumns / inlineAmountField — optional overrides; columns are
// otherwise derived from this object's fields.
},
quantity: { type: 'number' },
amount: { type: 'currency' },
},
});
// PARENT `invoice`: the group places the lines and holds no fields
fieldGroups: [{ key: 'lines', label: 'Line Items', relatedList: 'invoice_line' }],

// CHILD `invoice_line`: its master_detail FK, declaring no `relatedList`
invoice: {
type: 'master_detail',
reference: 'invoice',
inlineTitle: 'Line Items', // optional grid title
// inlineColumns / inlineAmountField — optional overrides; columns are
// otherwise derived from this object's fields.
},
```

**Set `inlineEdit` only for true line-item / composition children** (invoice
lines, order items, expense lines) — the things a user enters *together with*
the parent. **Leave it off for associations** (comments, attachments, activity,
audit): those are also `master_detail` (cascade delete) but should NOT clutter
the parent's entry form — surface them as related lists on the detail page.
Name only true line-item / composition children (invoice lines, order items,
expense lines); leave associations (comments, attachments, activity, audit) as
tabs.

The rendering side, `subforms` overrides included: objectstack-ui → Master-Detail Forms.

#### Inline-edit form factor (`grid` vs `form`)

`inlineEdit` also picks how the children are entered:
`inlineEdit` only picks how a placed child's rows are entered:

```typescript
inlineEdit: true // auto — pick grid/form from the child's shape (default)
Expand All @@ -300,7 +294,7 @@ editable fields, else `grid`. Set the string to override.
behaviors purely from how you model the child + parent:

```typescript
// Parent
// Parent (a field group names invoice_line, as above)
Invoice = {
fields: {
tax_rate: Field.number({ label: 'Tax Rate (%)' }), // → live Subtotal/Tax/Total stack
Expand Down
10 changes: 6 additions & 4 deletions skills/objectstack-ui/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ Two more: [List Views](#list-views), [Actions](#actions).
with `columns` and `modalSize`. `tabbed` flags a required field only on its
own tab and overflows on a phone
([Form Views](./rules/list-views.md#form-views)).
2. **A record entered with its line items is `inlineEdit` on the child's
`master_detail` field**, before any custom page, and its grid needs no "Add
line" button. A parent or child declaring `enable.apiMethods` must list
`'bulk'`, or the save is refused `405`
2. **A record entered with its line items is a parent field group naming the
child** (`fieldGroups: [{ key: 'lines', label: 'Lines', relatedList:
'invoice_line' }]`), before any custom page; without it nothing changes:
the child is a tab and the form has no lines, whatever `inlineEdit` says.
Its grid needs no "Add line" button. A parent or child declaring
`enable.apiMethods` must list `'bulk'`, or the save is refused `405`
([Master-Detail Forms](./rules/list-views.md#master-detail-forms-parent--child-line-items)).
3. **A persisted chart binds a declared dataset.** A widget or report names a
`defineDataset` and selects its `dimensions` / `values` by name; an object
Expand Down
4 changes: 2 additions & 2 deletions skills/objectstack-ui/evals/views-apps-actions-pages.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@
{
"id": 6,
"prompt": "Invoice entry as a stepped form — header, then line items, then review — saving the invoice and its lines together.",
"expected_output": "A stepped form over ONE object is `formViews` with `type: 'wizard'` and `sections`, not a screen flow (nothing branches). Line items come from the DATA MODEL: `inlineEdit` on the child's `master_detail` field, which renders the editable grid and saves parent + children in one atomic `/api/v1/batch`; `subforms` only to override derived columns. No custom page, and no 'Add line' button (the ghost row exists).",
"expected_output": "A stepped form over ONE object is `formViews` with `type: 'wizard'` and `sections`, not a screen flow (nothing branches). Line items come from the DATA MODEL: a field group of `invoice` naming the `master_detail` child (`fieldGroups: [{ key: 'lines', label: 'Lines', relatedList: 'invoice_line' }]`), which draws the editable grid in the form and saves parent + children in one atomic `/api/v1/batch`; without the group the form has no lines, whatever `inlineEdit` says. `subforms` only to override derived columns. No custom page, and no 'Add line' button (the ghost row exists).",
"files": [],
"assertions": {
"must_contain": ["type: 'wizard'", "inlineEdit", "formViews", "master_detail"],
"must_contain": ["type: 'wizard'", "relatedList", "formViews", "master_detail"],
"must_not_contain": ["type: 'screen'"]
}
},
Expand Down
23 changes: 11 additions & 12 deletions skills/objectstack-ui/rules/list-views.md
Original file line number Diff line number Diff line change
Expand Up @@ -367,19 +367,19 @@ To let users enter a record **together with its child line items** (invoice +
lines, project + tasks) and save them **atomically**, you almost never need a
custom page or form config. Prefer, in order:

1. **Relationship `inlineEdit` (default, zero UI config).** Declare it in the
DATA MODEL — set `inlineEdit` on the child's `master_detail` field that
references the parent. Every standard New/Edit form for the parent (modal,
drawer, full-page) then auto-renders the children and saves parent + children
in one atomic `/api/v1/batch`. **No view metadata needed.** A parent or child
1. **A parent field group naming the child (zero view config).** In the DATA
MODEL, the parent declares `fieldGroups: [{ key: 'lines', label: 'Lines',
relatedList: 'invoice_line' }]`. Its standard New/Edit forms (modal,
drawer, full-page) then draw the children there and save parent + children
in one atomic `/api/v1/batch`. Without the group 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`. The
`true` / `'grid'` / `'form'` ladder and what each value picks:
`405 OBJECT_API_METHOD_NOT_ALLOWED`. `inlineEdit` only picks how rows are
edited, the `true` / `'grid'` / `'form'` ladder:
**objectstack-data → Relationships → Inline Editing**.

2. **Form view `subforms` (override / tuning).** Add to a form view only when you
need to override the derived columns/order, or expose a child the
relationship didn't mark inline:
need to override the derived columns/order, or inline a child no group names:

```typescript
form: {
Expand All @@ -395,9 +395,8 @@ custom page or form config. Prefer, in order:
3. **`object-master-detail-form` page block (bespoke layout).** Use a page only
for free-form layouts. Same `details: [{ childObject }]` shorthand.

**Line-item grid behaviors (`grid` mode).** The editable grid is a real
spreadsheet-style line editor, and
every behaviour is derived from the DATA MODEL — computed columns, catalog
**Line-item grid behaviors (`grid` mode).** Every behaviour of the editable
grid is derived from the DATA MODEL — computed columns, catalog
typeahead auto-fill, persisted drag-reorder, and the live Subtotal → Tax → Total
stack: **objectstack-data → Relationships → Inline Editing**. Three things are
authored on this side: a trailing **ghost** row always exists, so never add an
Expand Down
Loading