Hi @nix0x00 👋

Thank you for raising this question.

Now that prisma has launched relations feature, how can I actually utilize it.

To use joins, you will need to enable the new relationLoadStrategy, you'll first need to add the preview feature flag to the generator block of your Prisma Client:

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["relationJoins"]
}

Once that's done, you'll need to re-run prisma generate for this change to take effect and pick a relation load strategy in your queries.
Here is an example that uses the new join strategy:

const usersWithPosts = await prisma.user.findMany({
  relationLoadStrategy: "join", // or "query"
  include: {
    posts: true,
  },
});

You should note that you can choose between database level join and application level join. With database level join, you would use join as the value for the relationLoadStrategy and with application level join, you would use query. You can take a look at this blog post to learn more.

can following query be converted to prisma query so that I don't have to use raw query.

If you want to convert this raw SQL query into a Prisma query, you might need to use the groupBy method provided by Prisma. But, as of now, Prisma does not support grouping on relations or counting based on a relation, as mentioned in the Github discussion. So at the moment, it's not currently possible to convert your raw SQL query into a Prisma query due to the limitations of the groupBy method.

If this answers your question, it would be great if you could mark this Discussion as answered to indicate that it has been resolved.

Otherwise please let us know how else we can help you further or close the Discussion if it was resolved in some other way 🙏

🌐
GitHub
github.com › prisma › prisma › issues › 22759
Specify per-relation load strategy · Issue #22759 · prisma/prisma
January 22, 2024 - // If unspecified, it inherits the global default. relationLoadStrategy: 'join', where: { // Only load posts for a specific author. authorId: '123', }, include: { // Load `post.category` via JOIN. category: { loadStrategy: 'join' }, // Load `post.author` with a separate query. author: { loadStrategy: 'query', include: { // Inherits the default as specified in `relationLoadStrategy` at the top of this `findMany` call. // In this case `true` is equivalent to `{ loadStrategy: 'join' }`. It does NOT inherit the `loadStrategy` // specified for the `author` relationship. avatarImage: true, } }, // `true` is equivalent to `{ loadStrategy: 'join' }` here. bannerImage: true, }, }) You can remove author from the include, make a separate Prisma call to load the author, and then perform the "join" manually by iterating and attaching the author object to all the post objects.
Author   prisma
Top answer
1 of 1
1

Hi @nix0x00 👋

Thank you for raising this question.

Now that prisma has launched relations feature, how can I actually utilize it.

To use joins, you will need to enable the new relationLoadStrategy, you'll first need to add the preview feature flag to the generator block of your Prisma Client:

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["relationJoins"]
}

Once that's done, you'll need to re-run prisma generate for this change to take effect and pick a relation load strategy in your queries.
Here is an example that uses the new join strategy:

const usersWithPosts = await prisma.user.findMany({
  relationLoadStrategy: "join", // or "query"
  include: {
    posts: true,
  },
});

You should note that you can choose between database level join and application level join. With database level join, you would use join as the value for the relationLoadStrategy and with application level join, you would use query. You can take a look at this blog post to learn more.

can following query be converted to prisma query so that I don't have to use raw query.

If you want to convert this raw SQL query into a Prisma query, you might need to use the groupBy method provided by Prisma. But, as of now, Prisma does not support grouping on relations or counting based on a relation, as mentioned in the Github discussion. So at the moment, it's not currently possible to convert your raw SQL query into a Prisma query due to the limitations of the groupBy method.

If this answers your question, it would be great if you could mark this Discussion as answered to indicate that it has been resolved.

Otherwise please let us know how else we can help you further or close the Discussion if it was resolved in some other way 🙏

Discussions

Support new relation load strategy for SQL Server (`relationJoins` preview feature)
Documentation: https://www.prisma.io/docs/orm/prisma-client/queries/relation-queries#relation-load-strategies-preview More on github.com
🌐 github.com
5
March 4, 2024
`relationJoins` default to `query`
When you enable the relationJoins ... use the relationLoadStrategy option in your queries to specify whether you want to use a join or the original query-based approach. This allows you to opt-in to testing joins for specific queries while maintaining the existing behavior for others. First, enable the relationJoins preview feature in your schema.prisma ... More on github.com
🌐 github.com
2
1
December 4, 2024
Unclutter SQL queries generated with `relationLoadStrategy: join`
In versions 5.7.0 and 5.10.0 we released support for a new relation load strategy for PostgreSQL and MySQL as part of the relationJoins preview feature: Documentation: prisma.io/docs/orm/prisma-cli... More on github.com
🌐 github.com
0
March 20, 2024
Support `cursor` with `relationLoadStrategy: join`
In versions 5.7.0 and 5.10.0 we released support for a new relation load strategy for PostgreSQL and MySQL as part of the relationJoins preview feature: Documentation: prisma.io/docs/orm/prisma-cli... More on github.com
🌐 github.com
4
March 20, 2024
🌐
GitHub
github.com › prisma › prisma › discussions › 22288
Preview feature feedback: `relationJoins` · prisma/prisma · Discussion #22288
I don't know if you've seen it already, but we shipped a limited form of this in Prisma 5.8.0: you can specify whether to use JOINs or separate queries on a per Prisma query basis using the relationLoadStrategy argument, but it applies to all relations in the query.
Author   prisma
🌐
Prisma
prisma.io › home › relation queries › relation queries › relation queries › relation queries
Relation queries (Concepts) | Prisma Documentation
You can decide on a per-query-level how you want Prisma Client to execute a relation query (i.e. what load strategy should be applied) via the relationLoadStrategy option for PostgreSQL databases.
🌐
GitHub
github.com › prisma › prisma › issues › 23347
Support new relation load strategy for SQL Server (`relationJoins` preview feature) · Issue #23347 · prisma/prisma
March 4, 2024 - In versions 5.7.0 and 5.10.0 we released support for a new relation load strategy for PostgreSQL and MySQL as part of the relationJoins preview feature: Documentation: https://www.prisma.io/docs/orm/prisma-client/queries/relation-queries...
Author   prisma
🌐
GitHub
github.com › prisma › prisma › discussions › 25789
`relationJoins` default to `query` · prisma/prisma · Discussion #25789
December 4, 2024 - When you enable the relationJoins preview feature, you can use the relationLoadStrategy option in your queries to specify whether you want to use a join or the original query-based approach.
Author   prisma
🌐
New Releases
newreleases.io › project › github › prisma › prisma › release › 5.10.0
prisma/prisma 5.10.0 on GitHub
February 20, 2024 - 🌟 Help us spread the word about Prisma by starring the repo ☝️ or posting on X about the release. This release brings the optimizations for relation queries from the previous releases to MySQL as well! This means that by enabling the relationJoins Preview feature with the mysql database provider, you now also get access to the relationLoadStrategy option in relation queries that let you choose whether you want to merged relations on the application- or database-level.
Find elsewhere
🌐
GitHub
github.com › prisma › prisma › releases › tag › 5.8.0
Release 5.8.0 · prisma/prisma
When the relationJoins Preview feature is enabled, by default, the relation fetching strategy used is join. You can override the default behavior by using the relationLoadStrategy query option. To get started, enable the Preview feature: // schema.prisma generator client { provider = "prisma-client-js" previewFeatures = ["relationJoins"] } …
Author   prisma
🌐
GitHub
github.com › prisma › prisma › releases › tag › 5.10.0
Release 5.10.0 · prisma/prisma
🌟 Help us spread the word about Prisma by starring the repo ☝️ or posting on X about the release. This release brings the optimizations for relation queries from the previous releases to MySQL as well! This means that by enabling the relationJoins Preview feature with the mysql database provider, you now also get access to the relationLoadStrategy option in relation queries that let you choose whether you want to merged relations on the application- or database-level.
Author   prisma
🌐
GitHub
github.com › prisma › prisma › issues › 23565
Unclutter SQL queries generated with `relationLoadStrategy: join` · Issue #23565 · prisma/prisma
March 20, 2024 - In versions 5.7.0 and 5.10.0 we released support for a new relation load strategy for PostgreSQL and MySQL as part of the relationJoins preview feature: Documentation: prisma.io/docs/orm/prisma-client/queries/relation-queries#relation-lo...
Author   prisma
🌐
GitHub
github.com › prisma › prisma › issues › 23564
Support `cursor` with `relationLoadStrategy: join` · Issue #23564 · prisma/prisma
March 20, 2024 - In versions 5.7.0 and 5.10.0 we released support for a new relation load strategy for PostgreSQL and MySQL as part of the relationJoins preview feature: Documentation: prisma.io/docs/orm/prisma-client/queries/relation-queries#relation-lo...
Author   prisma
🌐
GitHub
github.com › prisma › prisma › issues › 26101
retrieve db provider/driver - Unknown argument `relationLoadStrategy`. Available options are marked with ?. · Issue #26101 · prisma/prisma
January 16, 2025 - For the relationLoadStrategy, which is not supported on sqlite I need to detect that then I could remove it from the query. await prismaClient.table.findUnique({ relationLoadStrategy: isSqlite ? undefined : 'join', select: { ...
Author   prisma
🌐
GitHub
github.com › prisma › prisma › issues › 28058
Bug: `unreachable` code section hit during concurrent `relationLoadStrategy: 'join'` queries · Issue #28058 · prisma/prisma
September 7, 2025 - Bug description If two queries with relationalLoadStrategry: 'join are running at once then both hit an unreachable error. It appears #26827 has been reimplemented in the new javascript drivers. Se...
Author   prisma
🌐
GitHub
github.com › prisma › prisma › releases › tag › 5.14.0
Release 5.14.0 · prisma/prisma
Full documentation for this feature can be found in the Prisma Client API Reference. Note: Because createManyAndReturn() uses the RETURNING clause, it is only supported by PostgreSQL, CockroachDB, and SQLite databases. At this time, relationLoadStrategy: join is not supported in createMany...
Author   prisma
🌐
Safety DB
data.safetycli.com › packages › pypi › prisma › changelog
prisma Changelog
Today, we are excited to share the `5.10.0` stable release 🎉 🌟 **Help us spread the word about Prisma by starring the repo ☝️ or [posting on X](https://twitter.com/intent/post?text=Check out the latest @prisma release v5.10.0 🚀 https://github.com/prisma/prisma/releases/tag/5.10.0) about the release.** Highlights Optimized relation queries in MySQL (Preview) This release brings the optimizations for relation queries from the previous releases to MySQL as well! This means that by enabling the `relationJoins` Preview feature with the `mysql` database provider, you now also get access to the `relationLoadStrategy` option in relation queries that let you choose whether you want to merged relations on the application- or database-level.
🌐
Prisma
prisma.io › blog › prisma-orm-now-lets-you-choose-the-best-join-strategy-preview
Choosing the Best Join Strategy in Prisma ORM: join vs query
February 21, 2024 - You pick the strategy per query with the relationLoadStrategy option, available on PostgreSQL, CockroachDB, and MySQL behind the relationJoins preview feature flag; once the flag is on, join is the default.
🌐
GitHub
github.com › prisma › prisma › issues › 23233
`relationJoins` MySQL converts nested Decimal to float · Issue #23233 · prisma/prisma
February 21, 2024 - When using relationLoadStrategy: 'join' in MySQL, retrieving nested models with Decimal fields seem to convert decimal values to floats. https://github.com/michaelhays/prisma-relationjoins-decimal
Author   prisma
🌐
GitHub
github.com › prisma › prisma › issues › 23346
Support new relation load strategy for MariaDB (`relationJoins` preview feature) · Issue #23346 · prisma/prisma
March 4, 2024 - In versions 5.7.0 and 5.10.0 we released support for a new relation load strategy for PostgreSQL and MySQL as part of the relationJoins preview feature: Documentation: https://www.prisma.io/docs/orm/prisma-client/queries/relation-queries...
Author   prisma
🌐
npm
npmjs.com › package › prisma › v › 5.8.0-integration-engines-5-8-0-36-feat-qe-implement-relationloadstrategy-api-d2f09986b7514e6bda7b9fa6b000aec0c4cd8180.1
prisma - npm
If the feature on the roadmap is linked to a GitHub issue, please make sure to leave a +1 on the issue and ideally a comment with your thoughts about the feature! ... Refer to our contribution guidelines and Code of Conduct for contributors. ... npm i prisma@5.8.0-integration-engines-5-8-0-36-feat-qe-implement-relationloadstrategy-api-d2f09986b7514e6bda7b9fa6b000aec0c4cd8180.1
🌐
Prisma
prisma.io › blog › prisma-6-better-performance-more-flexibility-and-type-safe-sql
Prisma 6: Better Performance, More Flexibility & Type-Safe SQL
November 28, 2024 - If you go through Prisma ORM releases on GitHub, you'll find that almost every release came with some kind of performance improvements.