Skip to content

Commit be227e1

Browse files
ymc9claude
andcommitted
fix(orm): respect field arrayness when casting @db.* fields
When a field with a @db.* attribute is also an array, the CAST type should use the array form (e.g., `text[]` instead of `text`). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent b48b553 commit be227e1

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

packages/orm/src/client/crud/dialects/base-dialect.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,8 +1164,11 @@ export abstract class BaseCrudDialect<Schema extends SchemaDef> {
11641164
? this.getSqlType(subFieldDef.type)
11651165
: undefined;
11661166
if (castSqlType) {
1167+
const castType = subFieldDef.array
1168+
? sql`${sql.raw(castSqlType)}[]`
1169+
: sql.raw(castSqlType);
11671170
jsonObject[field] =
1168-
sql`CAST(${sql.ref(`${subModel.name}.${field}`)} AS ${sql.raw(castSqlType)})`;
1171+
sql`CAST(${sql.ref(`${subModel.name}.${field}`)} AS ${castType})`;
11691172
} else {
11701173
jsonObject[field] = eb.ref(`${subModel.name}.${field}`);
11711174
}
@@ -1376,7 +1379,8 @@ export abstract class BaseCrudDialect<Schema extends SchemaDef> {
13761379
if (this.hasNativeTypeAttribute(fieldDef)) {
13771380
const sqlType = this.getSqlType(fieldDef.type);
13781381
if (sqlType) {
1379-
return sql`CAST(${sql.ref(ref)} AS ${sql.raw(sqlType)})`;
1382+
const castType = fieldDef.array ? sql`${sql.raw(sqlType)}[]` : sql.raw(sqlType);
1383+
return sql`CAST(${sql.ref(ref)} AS ${castType})`;
13801384
}
13811385
}
13821386

0 commit comments

Comments
 (0)