Drizzle TeamDT
Drizzle Team3y ago
9 replies
Bryan3

How to include all fields in partial select syntax

Hi, I'm trying to append the organization field using a leftjoin to the existing fields in contact like this:

      const response = (await db
        .select({
          ...contact,
          organization: {
            name: organization.name,
          },
        })
        .from(contact)
        .leftJoin(
          organization,
          eq(contact.organizationId, organization.id),
        )) 


The query works but the IDE is giving me the error:
Argument of type '{ organization: { name: PgColumn<{ name: "name"; tableName: "Organization"; dataType: "string"; columnType: "PgText"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: [string, ...string[]]; baseColumn: never; }, {}, {}>; }; ... 11 more ...; updatedAt: PgColumn<...>; }' is not assignable to parameter of type 'SelectedFields'.
  Property '_' is incompatible with index signature.


for the ...contact part.

What would be the correct syntax to do this? Thanks.
Was this page helpful?