tunisoft
tunisoft
DTDrizzle Team
Created by tunisoft on 8/20/2023 in #help
Is it possible to use nanoid for uuid?
Hi, I want to see if I can customize the uuid generation but I have no idea how to do it. Is there a code sample that I can follow? Thank you
2 replies
DTDrizzle Team
Created by tunisoft on 8/7/2023 in #help
Typescript enum to pgEnum
6 replies
DTDrizzle Team
Created by tunisoft on 7/7/2023 in #help
[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/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 });
// /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
// 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
7 replies