beyondcode/laravel-query-detector

Wrong relation name suggested?

jose-bittacora opened this issue · 5 comments

Hi! First of all for your hard work.

When I try to use this package, I get suggestions to fix N+1 problems as expected, but I get results like this:

Model: MyPackage\Products\Models\Product => Relation: OtherPackage\Models\VatRate - You should add with(OtherPackage\Models\VatRate) to eager-load this relation.

This is the relation in Product:

public function vatRate(): BelongsTo
{
    return $this->belongsTo(VatRate::class);
}

When I do that, I get an error (relation does not exist). Why is the package reporting class names instead of relation names? I have been hours trying to figure this out but I have failed. I'm completely sure that I am doing something wrong, but I don't know what it is.

The code is working so I guess that the relation is correct.

Thank you

I am facing the same problem. It is giving the name of Class and as far as I know there is no way to use class in relationship directly.

I have tried to use it in a 2 years old project and the same happens.

Does anyone have solution for this issue? Why author is not replying on any issue?

Current work around I've found is increasing value of QUERY_DETECTOR_THRESHOLD in your .env file and that warning will be hidden.