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 🙏

🌐
Prisma
prisma.io › home › relation queries › relation queries › relation queries › relation queries
Relation queries (Concepts) | Prisma Documentation
That means that it creates the JSON structures returned by Prisma Client already in the database which saves computation resources on the application level. You can use the relationLoadStrategy option on the top-level in any query that supports ...
🌐
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.
Discussions

Specify per-relation load strategy
Note: this feature is related to the relationJoins preview feature launched in Prisma 5.8.0, and was discussed here. Problem It is often beneficial to use joins to load relations in a query, but it is sometimes better to load the related... More on github.com
🌐 github.com
0
January 22, 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
Can I opt into join vs every query being join by default?
Hi @aliabbasrizvi To control the default behavior of relation queries and opt into the join strategy for specific queries, you can use the relationLoadStrategyrelationLoadStrategy option. This feature allows you to decide on a per-query basis how you want Prisma Client to execute a relation query. More on answeroverflow.com
🌐 answeroverflow.com
July 3, 2024
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
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 🙏

🌐
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
🌐
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
🌐
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
🌐
X
x.com › prisma › status › 2013552133304725948
Prisma Postgres on X: "Did you know that Prisma ORM lets you control how relations are loaded? Use relationLoadStrategy: 'join' | 'query': - join runs a single DB query with joins - query runs multiple simpler queries Check it out👇 https://t.co/dy9Ryoze03 https://t.co/4J0lGqc4I8" / X
Did you know that Prisma ORM lets you control how relations are loaded? Use relationLoadStrategy: 'join' | 'query': - join runs a single DB query with joins - query runs multiple simpler queries Check it out https://pris.ly/d/relation-queries…
Find elsewhere
🌐
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 - Up until Prisma ORM v5.7.0, Prisma ORM would always use the application-level JOIN strategy. However, with the v5.7.0 release, we now allow you to pick the best JOIN strategy for your use case, ensuring you can always get the best performance for your queries. To choose a join strategy, you can use the relationLoadStrategy option on relation queries, e.g.:
🌐
Nico's Blog
nico.fyi › blog › prisma-join-relation
The new join relation in Prisma | Nico's Blog
March 5, 2024 - const users = await prisma.user.findMany({ relationLoadStrategy: 'join', // or 'query'. The default is the new join strategy, so this can actually be omitted take: 10, include: { posts: { take: 3, }, }, })
🌐
Prisma
prisma.io › home › query optimization › query optimization › query optimization › query optimization
Query optimization | Prisma Documentation
You can perform the query with a database join by setting relationLoadStrategy to "join", ensuring that only one query is executed against the database. const users = await prisma.user.findMany({}); const userIds = users.map((x) => x.id); const posts = await prisma.post.findMany({ relationLoadStrategy: "join", where: { authorId: { in: userIds, }, }, });
🌐
Prisma
prisma.io › home › prisma client api › prisma client api › prisma client api
Prisma Client API | Prisma Documentation
const omitPassword = { password: true } satisfies Prisma.UserOmit; relationLoadStrategy specifies how a relation should be loaded from the database.
🌐
GitClear
gitclear.com › open_repos › prisma › prisma › release › 5.10.0
Prisma 5.10.0 Release - GitClear
🌟 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.
🌐
Answer Overflow
answeroverflow.com › m › 1258099361745866752
Can I opt into join vs every query being join by default? - Prisma
July 3, 2024 - Hi @aliabbasrizvi To control the default behavior of relation queries and opt into the join strategy for specific queries, you can use the relationLoadStrategyrelationLoadStrategy option. This feature allows you to decide on a per-query basis how you want Prisma Client to execute a relation query.
🌐
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
🌐
Safety DB
data.safetycli.com › packages › pypi › prisma › changelog
prisma Changelog
You can now load relation data using either of the following strategies: - `join` — uses `JOIN`s to fetch relation data - `query` — uses separate queries to fetch relation data 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: tsx // schema.prisma generator client { provider = "prisma-client-js" previewFeatures = ["relationJoins"] } …
🌐
Prisma
prisma.io › home › select fields › select fields › select fields › select fields › select fields
Select fields | Prisma Documentation
Since version 5.9.0, when doing a relation query with include or by using select on a relation field, you can also specify the relationLoadStrategy to decide whether you want to use a database-level join or perform multiple queries and merge the data on the application level.
🌐
Answer Overflow
answeroverflow.com › m › 1320599157211402270
How prisma handle with n+1 problem using relation strategy query instead of join? - Prisma
December 23, 2024 - Hey @Rev 👋 Have you seen this ... to query Prisma Client sends multiple separate queries to the database, it then joins the data on the application level, rather than in the database....
🌐
DeepWiki
deepwiki.com › prisma › docs › 5.3-relations-and-data-modeling
Relations and Data Modeling | prisma/docs | DeepWiki
November 11, 2025 - See content/200-orm/200-prisma-client/100-queries/037-relation-queries.mdx312-364 for explanation. ... Since version 5.8.0, the relationLoadStrategy option controls how Prisma Client fetches related data:
🌐
StudyRaid
app.studyraid.com › en › read › 11147 › 345644 › including-related-data
Including Related Data (Advanced Querying with Prisma Client)
Prisma Client offers two strategies for loading related data: join and query. The join strategy, which is the default, uses database-level joins to fetch all related data in a single query.
🌐
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