drizzle-orm not inferring type from soft relations

Hello, I have set up soft relations to products and prices, my schema looks like this:

export const PriceTable = pgTable(
    "price",
    {
        id: text("id").primaryKey(),
        productId: text("product_id")
            .notNull()
            .references(() => ProductTable.id),
        active: boolean("active").notNull(),
        currency: text("currency").notNull(),
        unitAmount: integer("unit_amount"),
        createdAt: timestamp("created_at").defaultNow()
    },
    (t) => ({
        productIdIdx: index("idx_price_productId").on(t.productId),
        idIdx: index("idx_price_id").on(t.id)
    })
);

export const priceRelations = relations(PriceTable, ({ one }) => ({
    product: one(ProductTable, {
        fields: [PriceTable.productId],
        references: [ProductTable.id]
    })
}));


This is the product table

export const ProductTable = pgTable("product", {
    id: text("id").primaryKey(),
    active: boolean("active").notNull(),
    name: text("name").notNull(),
    description: text("description"),
    image: text("image"),
    creditAmount: integer("credit_amount").notNull(),
    createdAt: timestamp("created_at").defaultNow(),
    metadata: json("metadata").$type<ProductMetadata>().notNull()
});

export const productRelations = relations(ProductTable, ({ one }) => ({
    price: one(PriceTable)
}));


I have checked that my schema setup is correct, I think. Now, I have this query:

const price = await ctx.db.query.PriceTable.findFirst({
    where: eq(PriceTable.id, input.priceId),
    with: {
          product: true
        }
});


And in the resulting data type I can see this:

const price: {
    id: string;
    createdAt: Date | null;
    active: boolean;
    productId: string;
    currency: string;
    unitAmount: number | null;
    product: any;
} | undefined

Why is the product typed as any? Can drizzle not infer the types correctly? Thank you for any help.
Was this page helpful?