Error loading books: TypeError: Cannot read properties of undefined (reading 'referencedTable')

I searched and found a similar github issue that mentioned to fix this, I have to relations generated by drizzle, but I can't find any relations automatically being generated.
No description
1 Reply
quantumleaps
quantumleapsOP21h ago
sample schema :
export const book = sqliteTable("books", {
id: text("id").primaryKey(),
title: text('title').notNull(),
description: text('description'),
isbn: text('isbn'),
authors: text('authors').notNull(),
language: text('language').notNull().default('english'),
createdAt: integer('created_at', { mode: 'timestamp' }).notNull(),
updatedAt: integer('updated_at', { mode: 'timestamp' }).notNull(),
});

export const bookImages = sqliteTable("book_images", {
id: text("id").primaryKey(),
bookId: text('book_id').notNull().references(() => book.id),
url: text('url').notNull(),
order: integer('order').notNull().default(0),
createdAt: integer('created_at', { mode: 'timestamp' }).notNull(),
updatedAt: integer('updated_at', { mode: 'timestamp' }).notNull(),
});

export const bookFiles = sqliteTable("book_files", {
id: text("id").primaryKey(),
bookId: text('book_id').notNull().references(() => book.id),
downloadUrl: text('download_url').notNull(),
fileType: text('file_type').notNull(),
fileSize: text('file_size').notNull(),
createdAt: integer('created_at', { mode: 'timestamp' }).notNull(),
updatedAt: integer('updated_at', { mode: 'timestamp' }).notNull(),
});

// Pricing & Inventory
export const pricing = sqliteTable('pricing', {
id: text('id').primaryKey(),
bookId: text('book_id').references(() => book.id),
price: real('price').notNull(),
currency: text('currency').notNull().default('USD'),
createdAt: integer('created_at', { mode: 'timestamp' }).notNull(),
updatedAt: integer('updated_at', { mode: 'timestamp' }).notNull(),
});
export const book = sqliteTable("books", {
id: text("id").primaryKey(),
title: text('title').notNull(),
description: text('description'),
isbn: text('isbn'),
authors: text('authors').notNull(),
language: text('language').notNull().default('english'),
createdAt: integer('created_at', { mode: 'timestamp' }).notNull(),
updatedAt: integer('updated_at', { mode: 'timestamp' }).notNull(),
});

export const bookImages = sqliteTable("book_images", {
id: text("id").primaryKey(),
bookId: text('book_id').notNull().references(() => book.id),
url: text('url').notNull(),
order: integer('order').notNull().default(0),
createdAt: integer('created_at', { mode: 'timestamp' }).notNull(),
updatedAt: integer('updated_at', { mode: 'timestamp' }).notNull(),
});

export const bookFiles = sqliteTable("book_files", {
id: text("id").primaryKey(),
bookId: text('book_id').notNull().references(() => book.id),
downloadUrl: text('download_url').notNull(),
fileType: text('file_type').notNull(),
fileSize: text('file_size').notNull(),
createdAt: integer('created_at', { mode: 'timestamp' }).notNull(),
updatedAt: integer('updated_at', { mode: 'timestamp' }).notNull(),
});

// Pricing & Inventory
export const pricing = sqliteTable('pricing', {
id: text('id').primaryKey(),
bookId: text('book_id').references(() => book.id),
price: real('price').notNull(),
currency: text('currency').notNull().default('USD'),
createdAt: integer('created_at', { mode: 'timestamp' }).notNull(),
updatedAt: integer('updated_at', { mode: 'timestamp' }).notNull(),
});
sample code :
const books = await db.query.book.findMany({
with: {
images: true,
files: true,
pricing: true,

}) ?? [];
const books = await db.query.book.findMany({
with: {
images: true,
files: true,
pricing: true,

}) ?? [];
do I need to define relations manually?

Did you find this page helpful?