[5.7] Allow adding additional $manyMethods when extending the model class #26307
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 custommethod that returns an instance of my particular relationship clas.
Changes
Access the $manyMethods property through
static::$manyMethods
instead ofModel::$manyMethods
. This both reduces coupling between the trait and the Modelclass 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.