staudenmeir / eloquent-has-many-deep

Laravel Eloquent HasManyThrough relationships with unlimited levels
MIT License
2.67k stars 157 forks source link

HasOneDeep is not generic #223

Closed ahoiroman closed 10 months ago

ahoiroman commented 10 months ago

I got this relation:

    /**
     * @return HasOneDeep<Key>
     */
    public function key(): HasOneDeep
    {
        return $this->hasOneDeepFromRelations($this->vault(), (new Vault())->key());
    }

But unfortunately, phpstan reports:

phpstan: PHPDoc tag @return contains generic type Staudenmeir\EloquentHasManyDeep\HasOneDeep<App\Models\Key> but class Staudenmeir\EloquentHasManyDeep\HasOneDeep is not generic.

What can I do about it?

staudenmeir commented 10 months ago

Hi @ahoiromanm Does the issue go away if you add this comment to vendor/staudenmeir/eloquent-has-many-deep/src/HasOneDeep.php?

/**
 * @template TRelatedModel of \Illuminate\Database\Eloquent\Model
 * @extends \Illuminate\Database\Eloquent\Relations\HasOneThrough<TRelatedModel>
 */
class HasOneDeep extends HasManyDeep
{
ahoiroman commented 10 months ago

Hi Jonas,

unfortunately it is not solving the problem. The error is exactly the same.

staudenmeir commented 10 months ago

Could be a caching issue, it works for me. Please run vendor/bin/phpstan clear-result-cache and try again.

ahoiroman commented 10 months ago

You are right. After clearing the cache it works with the changes you described.

staudenmeir commented 10 months ago

Great. I've released a new version with the comment.