diff --git a/src/Models/Relationship.php b/src/Models/Relationship.php index 790e4b2..155f3e1 100644 --- a/src/Models/Relationship.php +++ b/src/Models/Relationship.php @@ -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 ?: []); } } diff --git a/tests/FieldRelationshipTest.php b/tests/FieldRelationshipTest.php index 8def239..6a8b249 100644 --- a/tests/FieldRelationshipTest.php +++ b/tests/FieldRelationshipTest.php @@ -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()); + } }