grist-core
grist-core copied to clipboard
Lists of RecordSets cannot be typed as Reference List
Problem
Say in table Carts there's a column $Cart of type Reference List, pointing to a Foods table
In a third table (say, Customers), we want to list all Foods that are in a customer's cart.
Carts.lookupRecords(customer=$id).Cart
returns a "list of lists" ([Foods[[1, 2, 3]], Foods[[1]]]
) which is not handled properly by Grist when trying to type it as a Reference List
A fix is to return a flattened list using a list comprehension [el for val in Carts.lookupRecords(customer=$id).Cart for el in val]
An example document can be found here : https://docs.getgrist.com/bAjQhzJRgBJB/Issue-1130-Example/p/1
Proposed solution
Option 1 : Implement a FLATTEN_RECORDS_LIST
function that transforms a list of lists of records into a list of records. We should offer a deduplicate option to this function.
Option 2 : Make Grist handle those list of lists of records as a valid input for the Reference List type
WDYT ?