Skip to content
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

Improve relation return types #255

Merged

Conversation

SanderMuller
Copy link
Contributor

Relations currently signal that they return the following: @return \Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\belongsToManyOfDescendants<static>

While they don't create a relation query builder of static (the declaring model) but actually for the related model as passed as class string to the method. For example in User this code snipped:

    public function roles(): BelongsToManyOfDescendants
    {
        return $this->belongsToManyOfDescendants(Role::class);
    }

Currently the return type would say that User would be the query target, while it's actually Role. This PR adds the generic TRelatedModel of \Illuminate\Database\Eloquent\Model to these methods and updates @param string $related to @param class-string<TRelatedModel> $related so we can now define the return type as @return \Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\HasManyOfDescendants<TRelatedModel> correctly signalling that we are creating a query of the passed class string of TRelatedModel

@staudenmeir staudenmeir merged commit e8ebff0 into staudenmeir:main Aug 25, 2024
31 checks passed
@staudenmeir
Copy link
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants