Skip to content

Commit

Permalink
Merge pull request #55 from symbiote/fix-empty-array
Browse files Browse the repository at this point in the history
fix(MultiValueField) Fixed issue with setting an empty array as a val…
  • Loading branch information
nyeholt committed Mar 20, 2018
2 parents 7f412df + e4c5de2 commit 03e335d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/ORM/FieldType/MultiValueField.php
Expand Up @@ -61,7 +61,9 @@ public function getValues()
public function setValue($value, $record = null, $markChanged = true)
{
$this->changed = $this->changed || $markChanged;
if ($value) {
if (!is_null($value)) {
// so that subsequent getValue calls re-load the value item correctly
$this->value = null;
if (!is_string($value)) {
$value = $this->serializeValue($value);
}
Expand Down
13 changes: 13 additions & 0 deletions tests/MultiValueFieldTest.php
Expand Up @@ -59,6 +59,19 @@ public function testSetJsonStringAsProperty()
$this->assertEquals(['One', 'Two'], $obj->obj('MVField')->getValues());
}

public function testSetEmptyArrayAsValue() {

$field = new MultiValueField();

$field->setValue(['one' => 'one']);

$this->assertEquals(['one' => 'one'], $field->getValue());

$field->setValue([]);

$this->assertEquals([], $field->getValue());
}

public function testIsChanged()
{
$field = new MultiValueField();
Expand Down

0 comments on commit 03e335d

Please sign in to comment.