Skip to content

Commit

Permalink
Added condition for nullable polymorphic relation (#34972)
Browse files Browse the repository at this point in the history
  • Loading branch information
lBodia committed Oct 26, 2020
1 parent c5ab5f7 commit 6defe37
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Illuminate/Database/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,10 @@ public function load($relations)
*/
public function loadMorph($relation, $relations)
{
if (! $this->{$relation}) {
return $this;
}

$className = get_class($this->{$relation});

$this->{$relation}->load($relations[$className] ?? []);
Expand Down Expand Up @@ -562,6 +566,10 @@ public function loadCount($relations)
*/
public function loadMorphCount($relation, $relations)
{
if (! $this->{$relation}) {
return $this;
}

$className = get_class($this->{$relation});

$this->{$relation}->loadCount($relations[$className] ?? []);
Expand Down

0 comments on commit 6defe37

Please sign in to comment.