Internal error: TypeError: Cannot read properties of undefined (reading 'referencedTable')`

No idea what am I doing wrong, my query looks like:
db.query.ProductTable.findFirst({
where: eq(ProductTable.slug, productSlug),
with: {
category: true,
},
});
db.query.ProductTable.findFirst({
where: eq(ProductTable.slug, productSlug),
with: {
category: true,
},
});
Table:
export const ProductTable = pgTable(
'product',
{
id: serial('id').primaryKey().unique(),
categoryId: integer('category_id').references(() => CategoryTable.id),
...
},
(table) => {
return {
nameIdx: index('name_idx').on(table.name),
};
},
);

export const ProductRelations = relations(ProductTable, ({ one, many }) => ({
category: one(CategoryTable, {
fields: [ProductTable.categoryId],
references: [CategoryTable.id]
}),
images: many(ProductImageTable),
}));
export const ProductTable = pgTable(
'product',
{
id: serial('id').primaryKey().unique(),
categoryId: integer('category_id').references(() => CategoryTable.id),
...
},
(table) => {
return {
nameIdx: index('name_idx').on(table.name),
};
},
);

export const ProductRelations = relations(ProductTable, ({ one, many }) => ({
category: one(CategoryTable, {
fields: [ProductTable.categoryId],
references: [CategoryTable.id]
}),
images: many(ProductImageTable),
}));
Other side:
export const CategoryTable = pgTable('category', {
id: serial('id').primaryKey().unique()
...
});

export const CategoryRelations = relations(CategoryTable, ({ one, many }) => ({
cld: many(CategoryToChildTable, { relationName: 'parent' }),
product: one(ProductTable, {
fields: [CategoryTable.id],
references: [ProductTable.categoryId],
}),
}));
export const CategoryTable = pgTable('category', {
id: serial('id').primaryKey().unique()
...
});

export const CategoryRelations = relations(CategoryTable, ({ one, many }) => ({
cld: many(CategoryToChildTable, { relationName: 'parent' }),
product: one(ProductTable, {
fields: [CategoryTable.id],
references: [ProductTable.categoryId],
}),
}));
Any help please?
2 Replies
kajl_pl
kajl_plOP5mo ago
oh ffs... restarted project and now it works 🤦‍♂️
Supernova
Supernova2mo ago
m curious to see your project
Want results from more Discord servers?
Add your server