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

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

Merged
merged 3 commits into from Nov 29, 2022

Conversation

vmcvlad
Copy link
Contributor

@vmcvlad vmcvlad commented Nov 28, 2022

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
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.

None yet

2 participants