Simple ForeignKey With statement not working

Hi - I am attempting to use a with statement on a query and am getting this error: Cannot read properties of undefined (reading 'referencedTable') Here's the query:
await db.query.faves.findMany({
with: {
firstName: true,
middleName: true
}
await db.query.faves.findMany({
with: {
firstName: true,
middleName: true
}
Here is the schema
export const names = sqliteTable('names', {
id: integer('id').primaryKey(),
name: text('name').notNull(),
createdAt: integer('created_at', { mode: 'timestamp' }).notNull(),
})

export type Name = InferSelectModel<typeof names>

export const faves = sqliteTable('faves', {
id: integer('id').primaryKey(),
firstName: integer('first_name_id').references(() => names.id),
middleName: integer('middle_name_id').references(() => names.id),
createdAt: integer('created_at', { mode: 'timestamp' }).notNull(),
})
export const names = sqliteTable('names', {
id: integer('id').primaryKey(),
name: text('name').notNull(),
createdAt: integer('created_at', { mode: 'timestamp' }).notNull(),
})

export type Name = InferSelectModel<typeof names>

export const faves = sqliteTable('faves', {
id: integer('id').primaryKey(),
firstName: integer('first_name_id').references(() => names.id),
middleName: integer('middle_name_id').references(() => names.id),
createdAt: integer('created_at', { mode: 'timestamp' }).notNull(),
})
Do I need to add a relationship? From the docs - it seemed like the foreignkey would be enough. The "Faves" table is just a record of favorite combinations from the "Names" table.
Angelelz
Angelelz240d ago
The relations are necessary if you want to use the RQB