perevezencev
perevezencev
DTDrizzle Team
Created by perevezencev on 12/22/2023 in #help
Describe where statement for null children
Hello everyone. I have this code:
export type CategoryId = number & { __typeName: 'Category' };

export const categories = pgTable(
'categories',
{
id: uuid('id').$type<ProductId>().defaultRandom().primaryKey(),
createdAt: timestamp('createdAt').defaultNow().notNull(),
title: varchar('title').notNull(),
parentId: uuid('parent_id')
},
)

export const categoriesRelations = relations(categories, ({ one, many }) => ({
parent: one(categories, {
fields: [categories.parentId],
references: [categories.id],
}),
children: many(categories),
}))

drizzle.query.categories.findMany({
where: (categories, { isNull }) => {
// Property 'children' does not exist on type
return isNull(categories.children)
},
})
export type CategoryId = number & { __typeName: 'Category' };

export const categories = pgTable(
'categories',
{
id: uuid('id').$type<ProductId>().defaultRandom().primaryKey(),
createdAt: timestamp('createdAt').defaultNow().notNull(),
title: varchar('title').notNull(),
parentId: uuid('parent_id')
},
)

export const categoriesRelations = relations(categories, ({ one, many }) => ({
parent: one(categories, {
fields: [categories.parentId],
references: [categories.id],
}),
children: many(categories),
}))

drizzle.query.categories.findMany({
where: (categories, { isNull }) => {
// Property 'children' does not exist on type
return isNull(categories.children)
},
})
How to describe where statement, for get all category where children is empty?
2 replies