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

[5.7] Allow adding additional $manyMethods when extending the model class #26307

Merged
merged 1 commit into from
Oct 30, 2018
Merged

[5.7] Allow adding additional $manyMethods when extending the model class #26307

merged 1 commit into from
Oct 30, 2018

Conversation

spawnia
Copy link
Contributor

@spawnia spawnia commented Oct 30, 2018

Motivation

This allows adding additional $manyMethods when extending the model class
and still receive a correct guess for the relationship name.

I have to overwrite the BelongsToMany relationship class in my application.
To return such a relationship, i also extended the Model class with a custom
method that returns an instance of my particular relationship clas.

Changes

Access the $manyMethods property through static::$manyMethods instead of
Model::$manyMethods. This both reduces coupling between the trait and the Model
class and allows for extensibility.

Removed the name of guessBelongsToManyRelation from the list but still consider
it when analyzing the call stack. This makes $manyMethods more slim and easier
to override.

Removed findFirstMethodThatIsntRelation from $hasMany array, since it does not
appear anywhere in the code and seems to have been forgotten there.
It is also not really a name for a many-relationship method, so if it is needed,
i think there might be a better place for it.

This allows adding additional $manyMethods when extending the model class
and still receive a correct guess for the relationship name.

Removed the name of guessBelongsToManyRelation from the list but still consider
it when analyzing the call stack. This makes $manyMethods more slim and easier
to override.

Removed findFirstMethodThatIsntRelation from $hasMany array, since it does not
appear anywhere in the code and seems to have been forgotten there.
It is also not really a name for a many-relationship method, so if it is needed,
i think there might be a better place for it.
@spawnia spawnia changed the title Access the $manyMethods property through static::$manyMethods Allow adding additional $manyMethods when extending the model class Oct 30, 2018
@taylorotwell taylorotwell merged commit 7cef687 into laravel:5.7 Oct 30, 2018
@spawnia spawnia deleted the allow-overwriting-manyMethods branch October 30, 2018 15:49
@GrahamCampbell GrahamCampbell changed the title Allow adding additional $manyMethods when extending the model class [5.7] Allow adding additional $manyMethods when extending the model class Oct 30, 2018
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