Relations include query
For example If I have the following schema:
I'm trying the following query and it throws me an error:
The error is
How can I get a
export const sales = mysqlTable("Sales", {
id: int("id").autoincrement().notNull(),
startingDate: datetime("starting_date", { mode: 'string'}).notNull(),
expirationDate: datetime("expiration_date", { mode: 'string'}),
bundleId: int("BundleId").references(() => bundles.id, { onDelete: "set null", onUpdate: "cascade" } ),
},
(table) => {
return {
bundleId: index("BundleId").on(table.bundleId),
salesId: primaryKey(table.id),
}
});
export const bundles = mysqlTable("Bundles", {
id: int("id").autoincrement().notNull(),
amount: float("amount").notNull(),
name: varchar("name", { length: 255 }),
},
(table) => {
return {
bundlesId: primaryKey(table.id),
}
});I'm trying the following query and it throws me an error:
await db.query.sales.findFirst({
where: eq(sales.businessUserId, id),
orderBy: desc(sales.id),
with: {
bundles: true
},
});The error is
undefined is not an object (evaluating 'relation.referencedTable').How can I get a
Sale object with it's Bundle complete object instead of only the BundleId? To avoid having to do another query.