RFC 0082 — A related record in a cell: shown by its name, picked by searching
Status: implemented (2026-11-30) · Target: 0.66.0 · builds on RFC 0078, RFC 0079, RFC 0081 and RFC 0012 · see Decisions
Summary
An invoice belongs to a customer, a task to a project, a product to a
supplier. In a list, that column is a key today: team_id: 3. It shows
as "3", it can't be edited in the table (RFCs 0078–0081 left
belongs_to out), and a pasted "Acme" can't become one.
This RFC makes such a column a reference: shown by the record's name,
and picked by searching, as the form's Combobox already does.
<Table
page={list}
bind:query
columns={[
"number",
{
key: "customer_id",
label: "Customer",
ref: {
search: (term) => api.customers_index({ search: term, per_page: 20 }),
find: (id) => api.customers_show(id),
label: "name",
},
edit: "ref",
},
]}
oneditrow={(row, values) => api.invoices_update(row.id, { ...inputOf(row), ...values })}
/>
- A column's
refsays how to find the related record:search(term)(the parent's index command),find(id)(its show command), and which of its fields is the key (value,"id") and the name (label,"name"). - Shown by name: the table finds the names of the keys on the page, once each, and shows "Acme Ltd" where it showed "3". Copy, the CSV and the search use the name too.
edit: "ref"(andcreate: "ref") edits the cell with aComboboxoversearch, the key written, the name shown at once.- A paste of names finds each by searching, and takes the record whose name is exactly that. The same for Set on the selection (RFC 0080).
make:resourcewritesreffor abelongs_towhose parent has a resource, so a list shows names; with--inline, they're edited too.
Motivation
- A key is not what a user reads. A list of invoices with "3", "7",
"3" in the customer column is a list the user can't use without
opening each row. Apps write a
formatwith a lookup of their own, or an index command that joins the name in, for every such column. - The table edits everything but these. RFCs 0078–0081 edit text, numbers, dates, booleans and options in place, and paste, fill and set them. A related record is often the very column a bulk change is for: "move these 40 tasks to the new project".
- The pieces exist.
Comboboxsearches a command and keeps a label for a value (RFC 0012);make:resourcealready finds a parent's resource (ParentView) and picks it in the form; the detail view already shows the parent's name from its_show.
Current state (0.67)
- A column shows
format(value, row), or the app'scellsnippet, or the value. A key shows as the key. editis"text","number","date","boolean"or{ options }; abelongs_toisn't edited in the table, andmake:resource --inlineleaves its column alone.- The form's
Comboboxsearches{parent}_index({ search, per_page: 20 })and shows the parent's first text field; the detail view finds the name with{parent}_show(id), live. - A paste, a fill and Set read a value by its column's kind
(
pastedValue), synchronously.
Design
A column's ref
ref?: {
search: (term: string, { signal }) => Promise<Row[] | Page<Row>>,
find?: (id) => Promise<Row>, // one record by its key
value?: string, // its key's field: "id"
label?: string | ((row) => string), // its name: "name"
}
Shown by name
- The names on the page: for the keys in a
refcolumn that the table has no name for, it callsfind(id), once for each key, at most six at a time. Until a name comes, the cell shows the key, muted; a key that can't be found stays shown as it is. - Kept by the table: the names are kept for as long as the table is there, for every page. A record picked or found by a search adds its name. A live page's re-run doesn't fetch them again.
- A row that has the name already (an index command that returns
customer: { id, name }next tocustomer_id) can say so with the column'sformatorcell, which still win;refthen only edits. - Copy, CSV, search, sort: Copy and the CSV have the name, and a
rowstable searches and sorts by it. A live page's sort is the command's, as it is today.
Edited
edit: "ref" (or create: "ref" for the new row only) makes the cell's
editor a Combobox with options={ref.search}: typing searches, ↓/↑
move, Enter picks and saves, Esc leaves it as it
was. The key is written (onedit(row, "customer_id", 7)); the name shows
at once, from the pick. Emptying the text writes null.
A ValidationError for the column opens the editor again with the
message, as for any cell (RFC 0078).
Pasted, filled and set
- Paste: a cell's text is a name. The table searches it with
search(text), and takes the one record whose name is the same text (case and surrounding space aside). None, or more than one: the value doesn't read, and the paste is refused, as RFC 0079 has it ("Row 4, Customer: no Acme found" / "two found"). The names are looked up before anything is written, at most six at a time, the same name once. - A key pasted (a cell copied from this table's own key) is taken as
the key when
findfinds it. - Fill down copies the key, and the name with it.
- Set (RFC 0080) gives the panel the
Combobox. - The new row (RFC 0081) picks it the same way.
make:resource
- A
belongs_towhose parent has a resource getsref: { search, find, label }in the list, from the parent's_indexand_showand its first text field (as the form uses), so the list shows the parent's name, with or without--inline. - With
--inline, it getsedit: "ref"; the first column'screatestays as it is.
Words
refNotFound(name), refMany(name), refLoading (the muted key's
description), in words.js and en/nb.
Implementation plan
ui/src/internal/refs.js: a column'srefwith its defaults, the names kept by key, finding the missing ones (six at a time, once each), and a name looked up by search (the one exact match).Table.svelte: the name in the cell, Copy, CSV, search and sort (plainOf,display), theComboboxas the cell's editor, the name kept from a pick, and a paste, fill and Set that look names up before writing.- Words, in
words.jsanden/nb. rata make:resource:reffor a parent with a resource, andedit: "ref"with--inline; tests and the smoke.- Tests: names found once and kept across pages, a key not found, the
editor's search, pick and Esc, emptying, a ValidationError, a paste of
names (found, not found, two found, the same name twice), a key
pasted, fill down, Set and the new row with a
ref,formatwinning, Copy and CSV with names. - Docs:
table.md("A related record"), a gallery example, the skills,resources.md, CHANGELOG.
Open questions
- Names by
find(id)one at a time, or afindMany(ids)? Recommendation:find, with an optionalfindMany(ids)used when it's given. A page has few distinct parents,_showis what every resource has, and afindManyis an optimization an app can add. - A paste with a name that matches more than one record? Recommendation: refused, as a value that doesn't read. Picking the first would write the wrong customer to 40 invoices without a word.
make:resourcelists show names without--inline? Recommendation: yes. A key in a list is never what a user wants, and it changes nothing the app relies on: the row's value is still the key.- Live names? Recommendation: not in this RFC. A parent renamed while the list is open shows its old name until the table is opened again; the detail view keeps its live name.
Decisions
Accepted 2026-11-30, with the open questions' recommendations:
- Names by
find(id), once a key, six at a time, and by an optionalfindMany(ids)when the app gives one. - A pasted name that matches more than one record is refused, as a value that doesn't read.
make:resourcelists show names without--inlinetoo; with it, the column is edited.- No live names in this RFC.
As built
As designed, with these differences:
- A key waiting for its name is shown as it is, not muted: a cell has no style of its own for it. A key that isn't found stays as it is.
- Typing on a related record's cell doesn't start its editor:
Enter, F2 or a double click opens the search,
from the cell's name. A typed character can't be handed to the
Comboboxas its first. refLoading(the muted key's description) isn't a word: nothing says a key is waiting.make:resource's lists render a parent's column with the table's text (cell(row, col, text)), so the name shows in the generatedcellsnippet too.
Not in this RFC
- Filtering a list by a related record (a
reffilter with search). - Sorting a live page by the related record's name (the command's own join).
- Many-to-many (
belongs_to_many) in a cell. - Live names, updated when the parent is renamed.
Alternatives considered
- The index command joins the name in. Every resource's command and its Laravel counterpart written again for each parent, and the edit still needs a search.
edit: { options }with every parent. Fine for five teams, not for 3,000 customers.- A
formatthat looks the name up. Synchronous: it can't call a command, so every app writes its own cache, asrefdoes once.