Can't use `where` clause?
Hi community, I don't know why, but I am not able to use the where clause.
Query:
However, the
export const packages = pgTable('package', {
id: serial('id').primaryKey().notNull(),
});
export const promotions = pgTable('promotion', {
id: serial('id').primaryKey().notNull(),
isActive: boolean('is_active').notNull().default(false),
});
export const packagePromotions = pgTable(
'package_promotion',
{
packageId: integer('package_id')
.notNull()
.references(() => packages.id),
promotionId: integer('promotion_id')
.notNull()
.references(() => promotions.id),
},
(table) => ({
pk: primaryKey({ columns: [table.packageId, table.promotionId] }),
}),
);
export const packagesRelations = relations(packages, ({ many}) => ({
packagePromotions: many(packagePromotions),
}));
export const promotionsRelations = relations(promotions, ({ many }) => ({
packages: many(packagePromotions),
}));
export const packagePromotionsRelations = relations(
packagePromotions,
({ one }) => ({
package: one(packages, {
fields: [packagePromotions.packageId],
references: [packages.id],
}),
promotion: one(promotions, {
fields: [packagePromotions.promotionId],
references: [promotions.id],
}),
}),
);
export const packages = pgTable('package', {
id: serial('id').primaryKey().notNull(),
});
export const promotions = pgTable('promotion', {
id: serial('id').primaryKey().notNull(),
isActive: boolean('is_active').notNull().default(false),
});
export const packagePromotions = pgTable(
'package_promotion',
{
packageId: integer('package_id')
.notNull()
.references(() => packages.id),
promotionId: integer('promotion_id')
.notNull()
.references(() => promotions.id),
},
(table) => ({
pk: primaryKey({ columns: [table.packageId, table.promotionId] }),
}),
);
export const packagesRelations = relations(packages, ({ many}) => ({
packagePromotions: many(packagePromotions),
}));
export const promotionsRelations = relations(promotions, ({ many }) => ({
packages: many(packagePromotions),
}));
export const packagePromotionsRelations = relations(
packagePromotions,
({ one }) => ({
package: one(packages, {
fields: [packagePromotions.packageId],
references: [packages.id],
}),
promotion: one(promotions, {
fields: [packagePromotions.promotionId],
references: [promotions.id],
}),
}),
);
const result = await db.query.packages.findFirst({
where: eq(packages.id, packageId),
with: {
packagePromotions: {
with: {
promotion: {
where: eq(promotions.isActive, true),
},
},
},
},
});
const result = await db.query.packages.findFirst({
where: eq(packages.id, packageId),
with: {
packagePromotions: {
with: {
promotion: {
where: eq(promotions.isActive, true),
},
},
},
},
});
where
clause inside promotion
does not exist. The goal its to get only the actived promotions. What am I missing? 🤔 Thank you!
0 Replies