Skip to content

Commit

Permalink
Merge pull request #32613 from laravel/issue-26126
Browse files Browse the repository at this point in the history
[6.x] Only restore common relations
  • Loading branch information
taylorotwell authored Apr 30, 2020
2 parents 62aea7e + c613a18 commit dcaf8a8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Eloquent/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ public function getQueueableIds()
*/
public function getQueueableRelations()
{
return $this->isNotEmpty() ? $this->first()->getQueueableRelations() : [];
return $this->isEmpty() ? [] : array_intersect(...$this->map->getQueueableRelations()->all());
}

/**
Expand Down
18 changes: 18 additions & 0 deletions tests/Database/DatabaseEloquentCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,24 @@ public function testQueueableCollectionImplementationThrowsExceptionOnMultipleMo
$c->getQueueableClass();
}

public function testQueueableRelationshipsReturnsOnlyRelationsCommonToAllModels()
{
// This is needed to prevent loading non-existing relationships on polymorphic model collections (#26126)
$c = new Collection([new class {
public function getQueueableRelations()
{
return ['user'];
}
}, new class {
public function getQueueableRelations()
{
return ['user', 'comments'];
}
}]);

$this->assertEquals(['user'], $c->getQueueableRelations());
}

public function testEmptyCollectionStayEmptyOnFresh()
{
$c = new Collection;
Expand Down

0 comments on commit dcaf8a8

Please sign in to comment.