Skip to content

[9.x] Address Dynamic Relation Resolver inconsiency issue with extended Models - #45122

Merged
taylorotwell merged 3 commits into
laravel:9.xfrom
vmcvlad:dynamic-relations-inheritance-issue
Nov 29, 2022
Merged

[9.x] Address Dynamic Relation Resolver inconsiency issue with extended Models#45122
taylorotwell merged 3 commits into
laravel:9.xfrom
vmcvlad:dynamic-relations-inheritance-issue

Conversation

@vmcvlad

@vmcvlad vmcvlad commented Nov 28, 2022

Copy link
Copy Markdown
Contributor

This PR aims to address the inconsistency issues with child Eloquent Models not inheriting their parents' dynamically registered relations, an issue which I attempted to explain in detail in #44741.

I have also added an in-line comment with an alternative approach to implementing the relationResolver() method.

* @return mixed
*/
public function relationResolver($class, $key)
{

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternative implementation:

public function relationResolver($key)
{
    $class = static::class;

    do {
        $resolver = static::$relationResolvers[$class][$key] ?? null;
    } while (!$resolver && $class = get_parent_class($class));

     return $resolver;
}

@vmcvlad
vmcvlad marked this pull request as ready for review November 28, 2022 13:07
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