[PR #5730] feat: adapter join support #14430

Closed
opened 2026-04-13 09:28:17 -05:00 by GiteaMirror · 0 comments
Owner

Original Pull Request: https://github.com/better-auth/better-auth/pull/5730

State: closed
Merged: Yes


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.

**Original Pull Request:** https://github.com/better-auth/better-auth/pull/5730 **State:** closed **Merged:** Yes --- # 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. -->
GiteaMirror added the pull-request label 2026-04-13 09:28:17 -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#14430