P
Prisma•6mo ago
aliabbasrizvi

Can I opt into join vs every query being join by default?

Hi I am looking to try the relationJoins feature, but looks like enabling it enables it for all queries and then you have the option to opt out of it. Is there a configuration where I can control the default behavior (I'd like to leave it as query) and then slowly opt into join for some queries?
4 Replies
RaphaelEtim
RaphaelEtim•6mo ago
Hi @aliabbasrizvi 👋 To control the default behavior of relation queries and opt into the join strategy for specific queries, you can use the relationLoadStrategy option. This feature allows you to decide on a per-query basis how you want Prisma Client to execute a relation query. You can opt into join for specific queries by specifying the join strategy for individual queries as needed. For example:
const result = await prisma.user.findMany({
include: {
posts: true,
},
relationLoadStrategy: 'join', // Opt into join for this specific query
});
const result = await prisma.user.findMany({
include: {
posts: true,
},
relationLoadStrategy: 'join', // Opt into join for this specific query
});
This way, you can keep the default behavior as query and selectively opt into join for specific queries.
Relation queries (Concepts) | Prisma Documentation
Prisma Client provides convenient queries for working with relations, such as a fluent API, nested writes (transactions), nested reads and relation filters.
aliabbasrizvi
aliabbasrizviOP•5mo ago
In understand this, but the problem is that if you have a 100 queries and you want to start trying the feature for only 2 queries say then you would have to update the code for 98 queries I wish to have the ability to be able to set default behavior at start and then opt into the new join strategy
Lord Zd
Lord Zd•5mo ago
I believe join is the default behavior for relationLoadStratergy so you would have to opt out of join in the queries where you dont want to use it assuming you are using a recent prisma version
aliabbasrizvi
aliabbasrizviOP•5mo ago
ok
Want results from more Discord servers?
Add your server