Skip to content

Commit

Permalink
Fixed a bug related with dataToDatabase
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed Feb 20, 2014
1 parent 167b355 commit 93c3dfc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 8 additions & 4 deletions SimpleCrud/Row.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use SimpleCrud\Entity;

class Row implements HasEntityInterface, \JsonSerializable {
private $values;
private $values = [];
private $changes = [];

public $entity;
Expand All @@ -19,11 +19,15 @@ public function __construct (Entity $entity, array $data = null, $onlyDeclaredFi
$this->entity = $entity;
$this->manager = $entity->manager;

if ($onlyDeclaredFields === true) {
$data = array_intersect_key($data, $this->entity->getFieldsNames());
if ($data) {
if ($onlyDeclaredFields === true) {
$data = array_intersect_key($data, $this->entity->getFieldsNames());
}

$this->values = $data;
}

$this->values = ($data ?: array()) + $entity->getDefaults();
$this->values += $entity->getDefaults();
}


Expand Down
4 changes: 4 additions & 0 deletions tests/SimpleCrudTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ public function testDataToDatabase () {

$row->set(['field1' => 'bye'])->save();
$this->assertSame($row->field1, $row->field2);

//Empty value
$row = $db->testing->create()->save();
$this->assertSame($row->field1, $row->field2);
}

public function testDatetimeFields () {
Expand Down

0 comments on commit 93c3dfc

Please sign in to comment.