Maximum call stack exceeded with relation to self

I have the following table
export const category = pgTable('categories', {
id: serial('id').primaryKey().notNull(),
parentCategoryId: integer('parent_category_id').references((): AnyPgColumn => category.id)
});

// relation
export const categoryRelations = relations(category, ({ many, one }) => ({
categories: many(category),
parentCategory: one(category, {
fields: [category.parentCategoryId],
references: [category.id]
})
}));
export const category = pgTable('categories', {
id: serial('id').primaryKey().notNull(),
parentCategoryId: integer('parent_category_id').references((): AnyPgColumn => category.id)
});

// relation
export const categoryRelations = relations(category, ({ many, one }) => ({
categories: many(category),
parentCategory: one(category, {
fields: [category.parentCategoryId],
references: [category.id]
})
}));
I am running the following query
db.select().from(category).where(isNull(category.parentCategoryId));
db.select().from(category).where(isNull(category.parentCategoryId));
and I am getting a maximum call stack exceeded error, here is the full log
Maximum call stack size exceeded
RangeError: Maximum call stack size exceeded
at file:///Users/john/Desktop/project/node_modules/.pnpm/drizzle-orm@0.26.1_postgres@3.3.4/node_modules/drizzle-orm/relations-c9e54a8f.mjs:517:17
at Array.map (<anonymous>)
at SQL.buildQueryFromSourceParams (file:///Users/john/Desktop/project/node_modules/.pnpm/drizzle-orm@0.26.1_postgres@3.3.4/node_modules/drizzle-orm/relations-c9e54a8f.mjs:515:36)
at file:///Users/john/Desktop/project/node_modules/.pnpm/drizzle-orm@0.26.1_postgres@3.3.4/node_modules/drizzle-orm/relations-c9e54a8f.mjs:594:29
at Array.map (<anonymous>)
at SQL.buildQueryFromSourceParams (file:///Users/john/Desktop/project/node_modules/.pnpm/drizzle-orm@0.26.1_postgres@3.3.4/node_modules/drizzle-orm/relations-c9e54a8f.mjs:515:36)
at file:///Users/john/Desktop/project/node_modules/.pnpm/drizzle-orm@0.26.1_postgres@3.3.4/node_modules/drizzle-orm/relations-c9e54a8f.mjs:594:29
at Array.map (<anonymous>)
at SQL.buildQueryFromSourceParams (file:///Users/john/Desktop/project/node_modules/.pnpm/drizzle-orm@0.26.1_postgres@3.3.4/node_modules/drizzle-orm/relations-c9e54a8f.mjs:515:36)
at file:///Users/john/Desktop/project/node_modules/.pnpm/drizzle-orm@0.26.1_postgres@3.3.4/node_modules/drizzle-orm/relations-c9e54a8f.mjs:594:29
Maximum call stack size exceeded
RangeError: Maximum call stack size exceeded
at file:///Users/john/Desktop/project/node_modules/.pnpm/drizzle-orm@0.26.1_postgres@3.3.4/node_modules/drizzle-orm/relations-c9e54a8f.mjs:517:17
at Array.map (<anonymous>)
at SQL.buildQueryFromSourceParams (file:///Users/john/Desktop/project/node_modules/.pnpm/drizzle-orm@0.26.1_postgres@3.3.4/node_modules/drizzle-orm/relations-c9e54a8f.mjs:515:36)
at file:///Users/john/Desktop/project/node_modules/.pnpm/drizzle-orm@0.26.1_postgres@3.3.4/node_modules/drizzle-orm/relations-c9e54a8f.mjs:594:29
at Array.map (<anonymous>)
at SQL.buildQueryFromSourceParams (file:///Users/john/Desktop/project/node_modules/.pnpm/drizzle-orm@0.26.1_postgres@3.3.4/node_modules/drizzle-orm/relations-c9e54a8f.mjs:515:36)
at file:///Users/john/Desktop/project/node_modules/.pnpm/drizzle-orm@0.26.1_postgres@3.3.4/node_modules/drizzle-orm/relations-c9e54a8f.mjs:594:29
at Array.map (<anonymous>)
at SQL.buildQueryFromSourceParams (file:///Users/john/Desktop/project/node_modules/.pnpm/drizzle-orm@0.26.1_postgres@3.3.4/node_modules/drizzle-orm/relations-c9e54a8f.mjs:515:36)
at file:///Users/john/Desktop/project/node_modules/.pnpm/drizzle-orm@0.26.1_postgres@3.3.4/node_modules/drizzle-orm/relations-c9e54a8f.mjs:594:29
hachoter
hachoter355d ago
I removed the relation and it's still not working, when I remove the where it is working
Siris
Siris355d ago
are you in a monorepo? see #maximum call stack exceeded