[GH-ISSUE #4479] drizzle integration doesn't create relations #9950

Closed
opened 2026-04-13 05:47:54 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @proof-llc on GitHub (Sep 5, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/4479

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. configure drizzle
  2. generate schema file

Current vs. Expected behavior

tables are created but no relations (https://orm.drizzle.team/docs/relations). I stumbled on this issue when i tried using with syntax (https://orm.drizzle.team/docs/rqb#select-filters) in drizzle - it wouldn't give me an tables to choose - adding the relations manually fixed it. Would be great to include the relations so help prevent the confusion that i had to go through.

What version of Better Auth are you using?

1.3.8

System info

{
  "system": {
    "platform": "darwin",
    "arch": "arm64",
    "version": "Darwin Kernel Version 24.6.0: Mon Jul 14 11:30:40 PDT 2025;",
    "release": "24.6.0",
    "cpuCount": 16,
    "cpuModel": "redacted",
    "totalMemory": "128.00 GB",
    "freeMemory": "20.62 GB"
  },
  "node": {
    "version": "v24.7.0",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "11.5.1"
  },
  "frameworks": null,
  "databases": null,
  "betterAuth": {
    "version": "0.1.0",
    "config": null
  }
}

Which area(s) are affected? (Select all that apply)

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  database: drizzleAdapter(db, {
      provider: 'sqlite',
      schema,
    })
});

Additional context

No response

Originally created by @proof-llc on GitHub (Sep 5, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/4479 ### Is this suited for github? - [ ] Yes, this is suited for github ### To Reproduce 1. configure drizzle 2. generate schema file ### Current vs. Expected behavior tables are created but no relations (https://orm.drizzle.team/docs/relations). I stumbled on this issue when i tried using `with` syntax (https://orm.drizzle.team/docs/rqb#select-filters) in drizzle - it wouldn't give me an tables to choose - adding the relations manually fixed it. Would be great to include the relations so help prevent the confusion that i had to go through. ### What version of Better Auth are you using? 1.3.8 ### System info ```bash { "system": { "platform": "darwin", "arch": "arm64", "version": "Darwin Kernel Version 24.6.0: Mon Jul 14 11:30:40 PDT 2025;", "release": "24.6.0", "cpuCount": 16, "cpuModel": "redacted", "totalMemory": "128.00 GB", "freeMemory": "20.62 GB" }, "node": { "version": "v24.7.0", "env": "development" }, "packageManager": { "name": "npm", "version": "11.5.1" }, "frameworks": null, "databases": null, "betterAuth": { "version": "0.1.0", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ database: drizzleAdapter(db, { provider: 'sqlite', schema, }) }); ``` ### Additional context _No response_
GiteaMirror added the locked label 2026-04-13 05:47:54 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Sep 5, 2025):

Better Auth's Drizzle integration generates tables and foreign key references (using .references()), so basic relations are present in the generated schema if your configuration is correct. However, it does not automatically generate Drizzle's higher-level .relations objects, which are needed for advanced features like the with syntax. You'll need to add those .relations objects manually to your schema for full Drizzle ORM relational support. This is a current limitation—there's no indication of plans for fully automated .relations generation yet. For best results, make sure your model naming matches your config (e.g., use the usePlural flag if your tables are pluralized) to avoid broken references in the generated schema [1] [2] [3].

If you run into circular reference issues when using relations, you can work around them by selecting only the fields you need or flattening returned objects [4].

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

<!-- gh-comment-id:3260060612 --> @dosubot[bot] commented on GitHub (Sep 5, 2025): <!-- Answer --> Better Auth's Drizzle integration generates tables and foreign key references (using `.references()`), so basic relations are present in the generated schema if your configuration is correct. However, it does not automatically generate Drizzle's higher-level `.relations` objects, which are needed for advanced features like the `with` syntax. You'll need to add those `.relations` objects manually to your schema for full Drizzle ORM relational support. This is a current limitation—there's no indication of plans for fully automated `.relations` generation yet. For best results, make sure your model naming matches your config (e.g., use the `usePlural` flag if your tables are pluralized) to avoid broken references in the generated schema [[1]](https://github.com/better-auth/better-auth/issues/3069) [[2]](https://github.com/better-auth/better-auth/pull/4132) [[3]](https://github.com/better-auth/better-auth/pull/4241). If you run into circular reference issues when using relations, you can work around them by selecting only the fields you need or flattening returned objects [[4]](https://github.com/better-auth/better-auth/issues/3813). <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/198fdf9c-ada1-4fe4-bdda-2d0fb6e0adf3?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/198fdf9c-ada1-4fe4-bdda-2d0fb6e0adf3?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/198fdf9c-ada1-4fe4-bdda-2d0fb6e0adf3?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/198fdf9c-ada1-4fe4-bdda-2d0fb6e0adf3?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/198fdf9c-ada1-4fe4-bdda-2d0fb6e0adf3?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/198fdf9c-ada1-4fe4-bdda-2d0fb6e0adf3?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/198fdf9c-ada1-4fe4-bdda-2d0fb6e0adf3?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/4479)
Author
Owner

@Kinfe123 commented on GitHub (Sep 6, 2025):

Right now. the adapter does not support join. so may be after we have a support for that that would really make sense to add it from there. so will be part of join release.

<!-- gh-comment-id:3262224191 --> @Kinfe123 commented on GitHub (Sep 6, 2025): Right now. the adapter does not support join. so may be after we have a support for that that would really make sense to add it from there. so will be part of join release.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#9950