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?
1 Reply
Angelelz
Angelelz9mo ago
I just replied to your question in the discussion. https://github.com/drizzle-team/drizzle-orm/discussions/1685
GitHub
How to describe where statement for null children? · drizzle-team d...
Hello everyone. I have this code: export type CategoryId = number & { __typeName: 'Category' }; export const categories = pgTable( 'categories', { id: uuid('id').$type&l...
Want results from more Discord servers?
Add your server