Explain the weirdness with enriched view FieldType.AI columns in a comment for the next person to stumble on this.

This commit is contained in:
Sam Rose 2025-01-08 17:09:02 +00:00
parent 1a6d27ae83
commit 352e16f347
No known key found for this signature in database
1 changed files with 15 additions and 0 deletions

View File

@ -432,6 +432,21 @@ export async function enrichSchema(
...tableSchema[key],
...ui,
order: anyViewOrder ? ui?.order ?? undefined : tableSchema[key]?.order,
// When this was written, the only column types in FieldSchema to have columns
// field were the relationship columns. We blank this out here to make sure it's
// not set on non-relationship columns, then below we populate it by calling
// populateRelSchema.
//
// For Budibase 3.0 we introduced the FieldType.AI fields. Some of these fields
// have `columns: string[]` and it flew under the radar here because the
// AIFieldMetadata type isn't a union on its subtypes, it has a collection of
// optional fields. So columns is `columns?: string[]` which allows undefined,
// and doesn't fail this type check.
//
// What this means in practice is when FieldType.AI fields get enriched, we
// delete their `columns`. At the time of writing, I don't believe anything in
// the frontend depends on this, but it is odd and will probably bite us at
// some point.
columns: undefined,
}