Skip to content

Commit

Permalink
Fixed empty relationship fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Bruckmaier committed Aug 13, 2023
1 parent 531071a commit 5af1a8d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Models/Relationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public function getValueAttribute()
{
// it would be nice if we could implement this as a hasMany()
// relation, but laravel does not support whereIn() in relationships
return $this->getSortedRelation(CorcelPost::class, $this->internal_value);
return $this->getSortedRelation(CorcelPost::class, $this->internal_value ?: []);
}
}
8 changes: 8 additions & 0 deletions tests/FieldRelationshipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,12 @@ public function testRelationshipField()
$this->assertInstanceOf(Collection::class, $acfField->value);
$this->assertEquals(['Post #0', 'Post #2', 'Post #1'], $acfField->value->pluck('post_title')->all());
}
public function testRelationshipFieldEmpty()
{
$acfField = factory(Relationship::class)->create();
$this->addData($acfField, 'fake_relationship_object', "");

$this->assertInstanceOf(Collection::class, $acfField->value);
$this->assertEquals([], $acfField->value->all());
}
}

0 comments on commit 5af1a8d

Please sign in to comment.