query with one to many (postgres + foreign keys)

I have the following schema:
export const accounts = pgTable("accounts", {
  id: serial("id").primaryKey(),
  address: text("address").notNull(),
  createdAt: timestamp("created_at").defaultNow().notNull(),
  updatedAt: timestamp("updated_at").defaultNow(),
  points: integer("points").default(0).notNull(),
});

export const nfts = pgTable("nfts", {
    id: serial("id").primaryKey(),
    contractAddress: text("contract_address").notNull(),
    tokenId: integer("token_id").notNull(),
    accountId: integer("account_id").references(() => accounts.id)
});


I am trying to query for a specific accounts and get all associated nfts with:
db.query.accounts.findFirst({
  where: eq(accounts.address, "0xDEAD...BEEF"),
  with: { nfts: true },
});

This results in the error: Invalid drizzle query.

Do I have to use drizzles relations to associate nfts to accounts instead of just foreign keys in order to use db.query?
Was this page helpful?