--level used: 2Phpstan/Larastan complains about ->withTrashed() calls on BelongsTo relationship definitions since version 0.6.6.
This was fine in version 0.6.5 and lower.
public function category(): BelongsTo
{
return $this->belongsTo(Category::class)->withTrashed();
}
public function supplier(): BelongsTo
{
return $this->belongsTo(Supplier::class)->withTrashed();
}
------ ---------------------------------------------------------------------------------------------------------------------------
Line Invoice/ReadModels/Mysql/EnteredInvoice.php
------ ---------------------------------------------------------------------------------------------------------------------------
93 Call to an undefined method Illuminate\Database\Eloquent\Relations\BelongsTo<Invoicr\Categories\Category>::withTrashed().
98 Call to an undefined method Illuminate\Database\Eloquent\Relations\BelongsTo<Invoicr\Suppliers\Supplier>::withTrashed().
------ ---------------------------------------------------------------------------------------------------------------------------
Hi,
I think in previous versions this was working by "mistake". Unknown method calls on relation was treated as DummyMethodReflection With the recent refactorings this is not the case anymore.
So I'd say this is a future request to support SoftDelete trait calls on relations.
@canvural any hints on how we could implement this support for SoftDelete? We expected larastan to get into the RelationForwardsCallsExtension extension, but it didn't seem to get into that code.
@WouterSioen Are checking it in the hasMethod method? It should get in there.
The problem in general is; here we just try to find the method in the builder. So before that line there needs to be a check like
if ($relatedModel->hasMethod($methodName)->yes()) {
return true;
}
Then in getMethod we need to check it again and return correct method reflection.
if ($relatedModel->hasMethod($methodName)->yes()) {
return new EloquentBuilderMethodReflection(.....);
}
Actually the check needs to happen if we can't find it in the builder. That makes more sense :+1:
Most helpful comment
Hi,
I think in previous versions this was working by "mistake". Unknown method calls on relation was treated as
DummyMethodReflectionWith the recent refactorings this is not the case anymore.So I'd say this is a future request to support
SoftDeletetrait calls on relations.