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/[email protected][email protected]/node_modules/drizzle-orm/relations-c9e54a8f.mjs:517:17
at Array.map (<anonymous>)
at SQL.buildQueryFromSourceParams (file:///Users/john/Desktop/project/node_modules/.pnpm/[email protected][email protected]/node_modules/drizzle-orm/relations-c9e54a8f.mjs:515:36)
at file:///Users/john/Desktop/project/node_modules/.pnpm/[email protected][email protected]/node_modules/drizzle-orm/relations-c9e54a8f.mjs:594:29
at Array.map (<anonymous>)
at SQL.buildQueryFromSourceParams (file:///Users/john/Desktop/project/node_modules/.pnpm/[email protected][email protected]/node_modules/drizzle-orm/relations-c9e54a8f.mjs:515:36)
at file:///Users/john/Desktop/project/node_modules/.pnpm/[email protected][email protected]/node_modules/drizzle-orm/relations-c9e54a8f.mjs:594:29
at Array.map (<anonymous>)
at SQL.buildQueryFromSourceParams (file:///Users/john/Desktop/project/node_modules/.pnpm/[email protected][email protected]/node_modules/drizzle-orm/relations-c9e54a8f.mjs:515:36)
at file:///Users/john/Desktop/project/node_modules/.pnpm/[email protected][email protected]/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/[email protected][email protected]/node_modules/drizzle-orm/relations-c9e54a8f.mjs:517:17
at Array.map (<anonymous>)
at SQL.buildQueryFromSourceParams (file:///Users/john/Desktop/project/node_modules/.pnpm/[email protected][email protected]/node_modules/drizzle-orm/relations-c9e54a8f.mjs:515:36)
at file:///Users/john/Desktop/project/node_modules/.pnpm/[email protected][email protected]/node_modules/drizzle-orm/relations-c9e54a8f.mjs:594:29
at Array.map (<anonymous>)
at SQL.buildQueryFromSourceParams (file:///Users/john/Desktop/project/node_modules/.pnpm/[email protected][email protected]/node_modules/drizzle-orm/relations-c9e54a8f.mjs:515:36)
at file:///Users/john/Desktop/project/node_modules/.pnpm/[email protected][email protected]/node_modules/drizzle-orm/relations-c9e54a8f.mjs:594:29
at Array.map (<anonymous>)
at SQL.buildQueryFromSourceParams (file:///Users/john/Desktop/project/node_modules/.pnpm/[email protected][email protected]/node_modules/drizzle-orm/relations-c9e54a8f.mjs:515:36)
at file:///Users/john/Desktop/project/node_modules/.pnpm/[email protected][email protected]/node_modules/drizzle-orm/relations-c9e54a8f.mjs:594:29
2 Replies
hachoter
hachoterOP2y ago
I removed the relation and it's still not working, when I remove the where it is working
Siris
Siris2y ago
are you in a monorepo? see #maximum call stack exceeded
Want results from more Discord servers?
Add your server