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.1] Added morph map #9891
[5.1] Added morph map #9891
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,13 @@ abstract class Relation | |
*/ | ||
protected static $constraints = true; | ||
|
||
/** | ||
* An array to map class names to their morph names in database. | ||
* | ||
* @var array | ||
*/ | ||
protected static $morphMap = []; | ||
|
||
/** | ||
* Create a new relation instance. | ||
* | ||
|
@@ -272,6 +279,22 @@ public function wrap($value) | |
return $this->parent->newQueryWithoutScopes()->getQuery()->getGrammar()->wrap($value); | ||
} | ||
|
||
/** | ||
* Set the morph map for polymorphic relations. | ||
* | ||
* @param array|null $map | ||
* @param bool $merge | ||
* @return array | ||
*/ | ||
public static function morphMap(array $map = null, $merge = true) | ||
{ | ||
if (is_array($map)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can reduce nesting by doing the reverse of this and early returning There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @GrahamCampbell Would that imply getting rid of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I'm saying do |
||
static::$morphMap = $merge ? array_merge(static::$morphMap, $map) : $map; | ||
} | ||
|
||
return static::$morphMap; | ||
} | ||
|
||
/** | ||
* Handle dynamic method calls to the relationship. | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can replace everything in this method with: