[PR #5730] [MERGED] feat: adapter join support #6183

Closed
opened 2026-03-13 12:50:21 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5730
Author: @ping-maxwell
Created: 11/2/2025
Status: Merged
Merged: 11/15/2025
Merged by: @Bekacru

Base: canaryHead: feat/adapter-join-support-v4


📝 Commits (10+)

  • 57808ce feat(adapter): Adapter Join support
  • 0483949 chore: lint
  • 594f4ac chore: fix CI for schema generations
  • d4f7710 Merge branch 'canary' into feat/adapter-join-support-v4
  • 1009c75 fix: type issues in generator files
  • 00a7fde fix: change req
  • 52bad7d fix: change req
  • ed0c103 update: support kysely and mongo & improve adapter factory
  • 49ed806 Merge remote-tracking branch 'upstream/canary' into feat/adapter-join-support-v4
  • 941f80c chore: lint

📊 Changes

81 files changed (+4739 additions, -968 deletions)

View changed files

.github/workflows/adapter-tests.yml (+67 -0)
📝 .github/workflows/ci.yml (+1 -1)
📝 docker-compose.yml (+14 -1)
📝 docs/content/docs/adapters/drizzle.mdx (+23 -0)
📝 docs/content/docs/adapters/mongo.mdx (+16 -0)
📝 docs/content/docs/adapters/mssql.mdx (+18 -0)
📝 docs/content/docs/adapters/mysql.mdx (+19 -0)
📝 docs/content/docs/adapters/postgresql.mdx (+18 -0)
📝 docs/content/docs/adapters/prisma.mdx (+21 -0)
📝 docs/content/docs/adapters/sqlite.mdx (+18 -0)
📝 docs/content/docs/concepts/database.mdx (+31 -0)
📝 docs/content/docs/guides/create-a-db-adapter.mdx (+60 -17)
📝 docs/content/docs/reference/options.mdx (+4 -1)
📝 packages/better-auth/package.json (+2 -1)
packages/better-auth/src/adapters/adapter-factory/get-default-field-name.ts (+63 -0)
packages/better-auth/src/adapters/adapter-factory/get-default-model-name.ts (+55 -0)
packages/better-auth/src/adapters/adapter-factory/get-field-attributes.ts (+62 -0)
packages/better-auth/src/adapters/adapter-factory/get-field-name.ts (+43 -0)
packages/better-auth/src/adapters/adapter-factory/get-id-field.ts (+150 -0)
packages/better-auth/src/adapters/adapter-factory/get-model-name.ts (+36 -0)

...and 61 more files

📄 Description

Adapter Join Support

image image

closes: https://github.com/better-auth/better-auth/issues/1298, https://github.com/better-auth/better-auth/issues/4201
linear: https://linear.app/better-auth/issue/ENG-33/feat-adapter-join-support

Adds adapter-level JOIN support to combine related reads (findOne/findMany) into one call. Also fixes foreign key generation and schema name handling so migrations and generators respect custom model/field names.

  • New Features

    • JOIN for findOne/findMany with inner/left joins and nested results (arrays for one-to-many, object for one-to-one).
    • Implemented across Drizzle, Kysely, MongoDB ($lookup), Memory, and Prisma (via include).
    • Exported helpers: getDefaultModelName, getDefaultFieldName, getModelName, getFieldName.
    • Added adapter config: disableTransformJoin.
    • Added join tests and a secondary Postgres service (postgres-kysely2) for testing.
    • Fallback join system in case a given adapter doesn't support it.
    • Updated documentation for creating adapters since it was extremely out of date.
    • Introduced experimental join support for Drizzle schema generation.
  • Bug Fixes

    • Kysely migrations now generate foreign keys using custom model/field names.
    • Prisma schema generation now honors custom names for relation fields.
    • CLI generators (Drizzle/Prisma) now resolve model/field names correctly when customized.

Info

  • Supports all adapters
  • Unit Tests
  • Documentation
  • Fallback Join system
  • Drizzle Schema generation supports relations

Example usage

image image

Summary by cubic

Adds adapter-level JOIN support for findOne/findMany to return related data in one call, with native or fallback joins across all adapters. Fixes foreign key and custom name handling so migrations and generators honor user-defined model and field names. Implements ENG-33.

  • New Features

    • JOINs for findOne/findMany (inner/left) with nested results.
    • Implemented in Drizzle, Kysely, Prisma (via include), MongoDB ($lookup), and Memory; automatic fallback when native joins are missing.
    • New config: disableTransformJoin and experimental.joins; exported helpers for model/field and ID resolution (initGetDefaultModelName/FieldName, initGetModelName/FieldName, initGetIdField, initGetFieldAttributes).
    • Updated adapter docs and tests; added a secondary Postgres service for Kysely; Drizzle schema relations generation; bumped drizzle-orm to 0.41.0.
  • Bug Fixes

    • Kysely migrations now generate foreign keys with custom model/field names.
    • Prisma schema generation now honors custom names for relation fields.
    • Improved schema name handling in migrations and generators.

Written for commit 5beca05073. Summary will update automatically on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/5730 **Author:** [@ping-maxwell](https://github.com/ping-maxwell) **Created:** 11/2/2025 **Status:** ✅ Merged **Merged:** 11/15/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `feat/adapter-join-support-v4` --- ### 📝 Commits (10+) - [`57808ce`](https://github.com/better-auth/better-auth/commit/57808cedffa9aed7f727501b1fa35708cc511513) feat(adapter): Adapter Join support - [`0483949`](https://github.com/better-auth/better-auth/commit/0483949fdaba59e4e970077df37826bb8773806d) chore: lint - [`594f4ac`](https://github.com/better-auth/better-auth/commit/594f4ac107016e10434da4816c72252642ec6ede) chore: fix CI for schema generations - [`d4f7710`](https://github.com/better-auth/better-auth/commit/d4f7710b8a167931d0e141b135807b4220bb4acd) Merge branch 'canary' into feat/adapter-join-support-v4 - [`1009c75`](https://github.com/better-auth/better-auth/commit/1009c75070cd9829b1c494da31b76a9eece6226d) fix: type issues in generator files - [`00a7fde`](https://github.com/better-auth/better-auth/commit/00a7fde3a28ee6507ab3a3e7371a76936b956220) fix: change req - [`52bad7d`](https://github.com/better-auth/better-auth/commit/52bad7df861dcf7b82abd288452fa6c439b1c1d4) fix: change req - [`ed0c103`](https://github.com/better-auth/better-auth/commit/ed0c103599ff1aa82b2e0fee4902c44ba7d9b45d) update: support kysely and mongo & improve adapter factory - [`49ed806`](https://github.com/better-auth/better-auth/commit/49ed80695900ba481fc67f9501f159a6f9069b9a) Merge remote-tracking branch 'upstream/canary' into feat/adapter-join-support-v4 - [`941f80c`](https://github.com/better-auth/better-auth/commit/941f80c9822c34f06664ff11a5a68ad6f68d8f45) chore: lint ### 📊 Changes **81 files changed** (+4739 additions, -968 deletions) <details> <summary>View changed files</summary> ➕ `.github/workflows/adapter-tests.yml` (+67 -0) 📝 `.github/workflows/ci.yml` (+1 -1) 📝 `docker-compose.yml` (+14 -1) 📝 `docs/content/docs/adapters/drizzle.mdx` (+23 -0) 📝 `docs/content/docs/adapters/mongo.mdx` (+16 -0) 📝 `docs/content/docs/adapters/mssql.mdx` (+18 -0) 📝 `docs/content/docs/adapters/mysql.mdx` (+19 -0) 📝 `docs/content/docs/adapters/postgresql.mdx` (+18 -0) 📝 `docs/content/docs/adapters/prisma.mdx` (+21 -0) 📝 `docs/content/docs/adapters/sqlite.mdx` (+18 -0) 📝 `docs/content/docs/concepts/database.mdx` (+31 -0) 📝 `docs/content/docs/guides/create-a-db-adapter.mdx` (+60 -17) 📝 `docs/content/docs/reference/options.mdx` (+4 -1) 📝 `packages/better-auth/package.json` (+2 -1) ➕ `packages/better-auth/src/adapters/adapter-factory/get-default-field-name.ts` (+63 -0) ➕ `packages/better-auth/src/adapters/adapter-factory/get-default-model-name.ts` (+55 -0) ➕ `packages/better-auth/src/adapters/adapter-factory/get-field-attributes.ts` (+62 -0) ➕ `packages/better-auth/src/adapters/adapter-factory/get-field-name.ts` (+43 -0) ➕ `packages/better-auth/src/adapters/adapter-factory/get-id-field.ts` (+150 -0) ➕ `packages/better-auth/src/adapters/adapter-factory/get-model-name.ts` (+36 -0) _...and 61 more files_ </details> ### 📄 Description # Adapter Join Support <img width="2404" height="1092" alt="image" src="https://github.com/user-attachments/assets/66f201fe-ec63-4c36-81ca-64c8cdc375c9" /> <img width="2280" height="1360" alt="image" src="https://github.com/user-attachments/assets/3f80359f-9f48-4faa-ac51-86e277643ecf" /> closes: https://github.com/better-auth/better-auth/issues/1298, https://github.com/better-auth/better-auth/issues/4201 linear: https://linear.app/better-auth/issue/ENG-33/feat-adapter-join-support Adds adapter-level JOIN support to combine related reads (findOne/findMany) into one call. Also fixes foreign key generation and schema name handling so migrations and generators respect custom model/field names. - **New Features** - JOIN for findOne/findMany with inner/left joins and nested results (arrays for one-to-many, object for one-to-one). - Implemented across Drizzle, Kysely, MongoDB ($lookup), Memory, and Prisma (via include). - Exported helpers: getDefaultModelName, getDefaultFieldName, getModelName, getFieldName. - Added adapter config: disableTransformJoin. - Added join tests and a secondary Postgres service (postgres-kysely2) for testing. - Fallback join system in case a given adapter doesn't support it. - Updated documentation for creating adapters since it was extremely out of date. - Introduced experimental join support for Drizzle schema generation. - **Bug Fixes** - Kysely migrations now generate foreign keys using custom model/field names. - Prisma schema generation now honors custom names for relation fields. - CLI generators (Drizzle/Prisma) now resolve model/field names correctly when customized. ## Info - [x] Supports all adapters - [x] Unit Tests - [x] Documentation - [x] Fallback Join system - [x] Drizzle Schema generation supports relations ## Example usage <img width="550" height="181" alt="image" src="https://github.com/user-attachments/assets/8d69c83b-89e0-401c-a326-5254fba16442" /> <img width="533" height="246" alt="image" src="https://github.com/user-attachments/assets/efd14fe8-5298-45fd-8e7f-23f02f2c6047" /> <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds adapter-level JOIN support for findOne/findMany to return related data in one call, with native or fallback joins across all adapters. Fixes foreign key and custom name handling so migrations and generators honor user-defined model and field names. Implements ENG-33. - **New Features** - JOINs for findOne/findMany (inner/left) with nested results. - Implemented in Drizzle, Kysely, Prisma (via include), MongoDB ($lookup), and Memory; automatic fallback when native joins are missing. - New config: disableTransformJoin and experimental.joins; exported helpers for model/field and ID resolution (initGetDefaultModelName/FieldName, initGetModelName/FieldName, initGetIdField, initGetFieldAttributes). - Updated adapter docs and tests; added a secondary Postgres service for Kysely; Drizzle schema relations generation; bumped drizzle-orm to 0.41.0. - **Bug Fixes** - Kysely migrations now generate foreign keys with custom model/field names. - Prisma schema generation now honors custom names for relation fields. - Improved schema name handling in migrations and generators. <sup>Written for commit 5beca050733f0ad838732e73d8ac4fb4dc87d376. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 12:50:21 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#6183