[solved] One to many relation not working

I get the error "There is not enough information to infer relation"

Here's (part of) my code

// /src/lib/schemas/db/fields.ts
export const fields = pgTable('fields', {
    id: serial('id').primaryKey(),
    name: varchar('name')
});

export const fields_lang = pgTable('fields_lang', {
    id: serial('id').primaryKey(),
    id_field: integer('id_field')
        .notNull()
        .references(() => fields.id),
    id_lang: serial('id_lang').notNull(),
    label: varchar('label')
});

export const fieldsRelations = relations(fields, ({ many }) => ({
    lang: many(fields_lang)
}));


// /src/lib/db/client.ts
import * as schema from '$lib/schemas/db/fields';

const pool = new Pool({
    connectionString: env.DB_URL
});

export const db = drizzle(pool, { schema });


// in some route code

const fields_rows = await db.query.fields.findMany({
    where: (fields, { eq }) => eq(fields.id_form, id),
    with: {
        lang: {
            where: (fields_lang, { eq }) => eq(fields_lang.id_field, fields.id)
        }
    }
});

// error: There is not enough information to infer relation


I must be missing something obvious
Was this page helpful?