beyondcode/laravel-query-detector

Issue when relation more than one same relation and no results.

maiconmva opened this issue · 3 comments

Hello, i think i found a issue,

I have this model with 3 relations with Person Model.

and when i filter to show some record without relations with persons the N+1 log shows...

image

But if u see the querie, shows the correct way, its not a N+1 error....
image

this is the n+1 log;
image

Do we have the same problem?
image

The query:
$subscription = Subscription::with('transaction')->where('tenant_id', tenant('id'))->first();

Yes it is. Have similar problem.
It is a false positive.

In my case below query is exactly the same but actually its a different context.

The first one is for getting post_author and the second one is for updater.

image

I have same issue with laravel-medialibrary

my code:
Activity::with(['categories', 'categories.image', 'categories.bannerImage'])->get()

saying:

local.INFO: Model: App\Models\Category
Relation: Spatie\MediaLibrary\MediaCollections\Models\Media
Num-Called: 2
Call-Stack:...

For now I set QUERY_DETECTOR_THRESHOLD=2 but what if i need some more eager loading with different relationship like categories.featureImage

It should use N+1 problem detection for same queries not for same model

@hussainalihussain