-
-
Notifications
You must be signed in to change notification settings - Fork 410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Relation getQuery() return type loses model generic #2069
Comments
Eeeeh it's probably me, because somewhere else:
It still knows about Maybe because my // No @return here
public function site_checks() : Relations\HasManyThrough {
return $this->hasManyThrough(SiteCheck::class, Site::class, 'organization_id', 'site_id');
} |
But if I add a /** @return Relations\HasManyThrough<SiteCheck<Checked>> */
public function site_checks() : Relations\HasManyThrough {
return $this->hasManyThrough(SiteCheck::class, Site::class, 'organization_id', 'site_id');
} phpstan complains about its return value:
because yeah kinda, because |
And with that |
Wow, generics are a lot of trouble with phpstan level 5+. Suddenly
Come ooon! That's good enough! |
Use the wildcard if you're not sure / don't care what the inner types will be: /** @return Relations\HasManyThrough<SiteCheck<*>> */
public function site_checks() : Relations\HasManyThrough {
return $this->hasManyThrough(SiteCheck::class, Site::class, 'organization_id', 'site_id');
} |
That's good to know, but that doesn't solve any part of the problem. /** @return Relations\HasManyThrough<SiteCheck<*>> */
public function site_checks() : Relations\HasManyThrough {
return $this->hasManyThrough(SiteCheck::class, Site::class, 'organization_id', 'site_id');
} doesn't do/change anything. Larastan makes the return type |
If I hack Larastan's
But that still doesn't fix the
It's still the base Model! Why doesn't it use |
I'll take a look. Is that the only relation or does it do that for all relation types? |
Omg I'm an idiot. \PHPStan\dumpType($contact->sites()); // 🟩 Relations\HasManyThrough<Site>
\PHPStan\dumpType($contact->sites()->getQuery()); // 🟥 EloquentBuilder<EloquentModel>
|
@rudiedirkx Could you try the latest |
Description
Phpstan understands the type of a model's relation query, but after
getQuery()
it loses the specific model/generic.Laravel code where the issue was found
In the last dump, the model becomes an eloquent model instead of
SiteCheck
. Which is weird, becausegetQuery()
in Laravel does have a return hint:and it still knew
TRelatedModel
the dump before.I don't get it. I don't even know who's doing it wrong. Me, Larastan, Phpstan, or Laravel?
The text was updated successfully, but these errors were encountered: