ITADN

[BUG]: can no longer obtain table name from column object

#5890Openfr33bits 创建于 2026-06-13
bug
F
fr33bitscommented
### Report hasn't been filed before. - [x] I have verified that the bug I'm about to report hasn't been filed before. ### What version of `drizzle-orm` are you using? 1.0.0-rc.3 ### What version of `drizzle-kit` are you using? 1.0.0-rc.3 ### Other packages _No response_ ### Describe the Bug Ever since upgrading from version `0.45.2` to `1.0.0-rc.3` I can no longer obtain the table name from a column object of a particular table. This used to be possible by accessing the `<column_object>._.tableName` property. TypeScript types would actually lead you to believe that this property is still accessible but actually the whole `<column_object>._` now appears to be undefined at runtime. For my use case I consider this a regression. I apply a `check()` on all string columns to ensure that the database does not accept empty strings. I rely on the table name to disambiguate the columns of the same name located in different tables. I used to be able to just read the table name from the first column (within the `validateStrings()` functions ) but now I need to store the table name in a separate variables (so that there's a single source of truth): ```ts const shortcutTableName = 'shortcut'; export const shortcutTable = snakeCase.table( shortcutTableName, { id: int().primaryKey().autoincrement(), userId: int() .notNull() .references(() => userTable.id, { onDelete: 'cascade' }), name: varchar({ length: MAX_STRING_LENGTH_GENERAL }).notNull(), url: varchar({ length: MAX_STRING_LENGTH_URL }).notNull(), orderIndex: int().notNull() }, (table) => validateStrings(table, shortcutTableName) // `table.name._.tableName` here has a type of 'shortcut' despite it being undefined at runtime ); export const validateStrings = <TTable extends MySqlTable>( columns: TableColumns<TTable>, tableName: string ) => { return Object.values(columns) .filter((column) => column.dataType === 'string') .map((column) => { return check( `ne-${tableName}.${column.name}`, sql`${column} IS NULL OR ( char_length(trim(${column})) > 0 AND char_length(trim(${column})) = char_length(${column}) )` ); }); }; ``` I'm not sure if `<column_object>._` is/was supposed to be some internal or legacy property but in any case either it needs to be readded (at runtime) or the types corrected.
1 条评论