2525 * - Only a stamp `withRecordBeingEdited` issued counts. The key written as
2626 * data — on a document's form field, an action's params — is no stamp, so
2727 * no host is opted in by what it is handed.
28- * - An entry whose referenced value is empty — null, unset, `''`, an empty
29- * list, a hop whose lookup is unset — is left out of the query, the rule an
30- * unset `dependsOn` parent follows.
28+ * - An entry whose referenced value is empty — null, unset, `''`, a hop whose
29+ * lookup is unset — is left out of the query, the rule an unset `dependsOn`
30+ * parent follows.
31+ * - A path through or to a multi-valued field — the record or the hop's row
32+ * holds a list there (`accounts.cb_market` through a `multiple: true`
33+ * lookup, `tags`, `account.markets`) — has no single value to compare, the
34+ * spec's rule (`LookupFilterRecordReferenceSchema`): its entry is left out,
35+ * never sent with the list as a scalar comparand, and a development build
36+ * says so once per path.
3137 * - A hop whose row cannot be read is left out the same way: the picker
3238 * narrows the choice only, and the save is the server's to judge.
3339 * - ⛔ No `{ $record }` value ever reaches the wire: `lookupFiltersToRecord`
@@ -170,8 +176,8 @@ export function readRecordBeingEdited(field: unknown): RecordBeingEdited | undef
170176}
171177
172178/**
173- * The value a `{ $record }` path names, or `undefined` when it is empty or
174- * cannot be read. `hopRows` holds the rows read for each hop's lookup, by
179+ * The value a `{ $record }` path names, or `undefined` when it is empty,
180+ * cannot be read, or is multi-valued (a list on the record or the hop's row) . `hopRows` holds the rows read for each hop's lookup, by
175181 * `via`; an expanded row on the record itself is read first, so a host that
176182 * already holds the related record costs no request.
177183 */
@@ -182,22 +188,28 @@ function readRecordPath(
182188) : unknown {
183189 const dot = path . indexOf ( '.' ) ;
184190 if ( dot < 0 ) {
185- const v = collapseReference ( record [ path ] ) ;
191+ const own = record [ path ] ;
192+ if ( Array . isArray ( own ) ) return warnMultiValuedPath ( path , `"${ path } " holds a list` ) ;
193+ const v = collapseReference ( own ) ;
186194 return isEmptyValue ( v ) ? undefined : v ;
187195 }
188196 const via = path . slice ( 0 , dot ) ;
189197 const field = path . slice ( dot + 1 ) ;
190198 const held = record [ via ] ;
199+ if ( Array . isArray ( held ) ) return warnMultiValuedPath ( path , `the lookup "${ via } " holds a list of records` ) ;
191200 if ( isEmptyValue ( held ) ) return undefined ;
192201 const row = isRow ( held ) && Object . prototype . hasOwnProperty . call ( held , field ) ? held : hopRows [ via ] ;
193202 if ( ! row ) return undefined ;
194- const v = collapseReference ( row [ field ] ) ;
203+ const end = row [ field ] ;
204+ if ( Array . isArray ( end ) ) return warnMultiValuedPath ( path , `"${ field } " on the "${ via } " row holds a list` ) ;
205+ const v = collapseReference ( end ) ;
195206 return isEmptyValue ( v ) ? undefined : v ;
196207}
197208
198209/**
199210 * `filters` with every `{ $record }` value replaced by the value it names on
200- * `record`, and every entry whose value is empty or unreadable left out.
211+ * `record`, and every entry whose value is empty, unreadable or multi-valued
212+ * left out.
201213 * Literal entries pass through untouched, in order.
202214 */
203215export function resolveLookupFilters (
@@ -218,24 +230,45 @@ export function resolveLookupFilters(
218230 return out ;
219231}
220232
221- const warnedHops = new Set < string > ( ) ;
233+ const warned = new Set < string > ( ) ;
222234
223235/**
224- * Said once per hop: the entry is left out, so the picker offers more than the
225- * author wrote — visible here rather than only as a wider list.
236+ * The development-build warning for an entry left out of the candidate query,
237+ * said once per `key`: the picker then offers more than the author wrote —
238+ * visible here rather than only as a wider list.
226239 */
227- function warnUnreadableHop ( via : string , field : string , object : string | undefined ) : void {
240+ function warnLeftOut ( key : string , path : string , reason : string ) : void {
228241 if ( ( globalThis as { process ?: { env ?: { NODE_ENV ?: string } } } ) . process ?. env ?. NODE_ENV === 'production' ) return ;
229- const key = `${ via } .${ field } ` ;
230- if ( warnedHops . has ( key ) ) return ;
231- warnedHops . add ( key ) ;
232- console . warn (
233- `[LookupField] lookupFilters { $record: "${ key } " } is left out of the candidate query: `
234- + ( object
235- ? `no data source here can read ${ object } rows.`
236- : `the record holds "${ via } " as an id, and this host did not name the object it points at `
237- + `(a record form stamps it with withRecordBeingEdited).` ) ,
242+ if ( warned . has ( key ) ) return ;
243+ warned . add ( key ) ;
244+ console . warn ( `[LookupField] lookupFilters { $record: "${ path } " } is left out of the candidate query: ${ reason } ` ) ;
245+ }
246+
247+ /** Said once per hop whose row cannot be read. */
248+ function warnUnreadableHop ( via : string , field : string , object : string | undefined ) : void {
249+ const path = `${ via } .${ field } ` ;
250+ warnLeftOut (
251+ `hop:${ path } ` ,
252+ path ,
253+ object
254+ ? `no data source here can read ${ object } rows.`
255+ : `the record holds "${ via } " as an id, and this host did not name the object it points at `
256+ + `(a record form stamps it with withRecordBeingEdited).` ,
257+ ) ;
258+ }
259+
260+ /**
261+ * Said once per path through or to a multi-valued field; answers `undefined`,
262+ * the value such a path resolves to.
263+ */
264+ function warnMultiValuedPath ( path : string , where : string ) : undefined {
265+ warnLeftOut (
266+ `multi:${ path } ` ,
267+ path ,
268+ `the path is multi-valued — ${ where } — and a { $record } path names a single value. `
269+ + 'Point it at a single-valued field.' ,
238270 ) ;
271+ return undefined ;
239272}
240273
241274interface HopSource {
0 commit comments