Created
January 4, 2024 04:59
-
-
Save stolinski/48d74aaae59895c9001128a69448eacc to your computer and use it in GitHub Desktop.
Error: There is not enough information to infer relation "__public__.habits.checks" at normalizeRelation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Schema | |
import { relations } from 'drizzle-orm'; | |
import { serial, text, timestamp, pgTable, date, integer } from 'drizzle-orm/pg-core'; | |
export const habits = pgTable('habits', { | |
id: serial('id').primaryKey(), | |
name: text('name'), | |
days_per_month: integer('days_per_month'), | |
created_at: timestamp('created_at'), | |
updated_at: timestamp('updated_at') | |
}); | |
export const habitRelations = relations(habits, ({ many }) => ({ | |
checks: many(habits) | |
})); | |
export const checks = pgTable('checks', { | |
id: serial('id').primaryKey(), | |
checked_at: date('date'), | |
habit_id: integer('habit_id') | |
}); | |
export const checkRelations = relations(checks, ({ one }) => ({ | |
habit: one(habits, { | |
fields: [checks.habit_id], | |
references: [habits.id] | |
}) | |
})); | |
// Query | |
const data = await db.query.habits.findMany({ | |
with: { | |
checks: true | |
} | |
}); | |
// Following https://orm.drizzle.team/docs/rqb#one-to-many |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In:
shouldn't it be
({ checks: many(checks)}));
?I wrote on Twitter but you deleted.