Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding a fix to retain fidelity on exporting document data as an array.

  • Loading branch information...
commit e8c2c6ab987ada54645ca0536df3963a4e0ff0e4 1 parent d64af2e
Howard Lince III Howard3 authored
Showing with 22 additions and 1 deletion.
  1. +2 −1  data/Entity.php
  2. +20 −0 tests/cases/data/entity/DocumentTest.php
3  data/Entity.php
View
@@ -11,6 +11,7 @@
use BadMethodCallException;
use UnexpectedValueException;
use lithium\data\Collection;
+use lithium\util\Set;
/**
* `Entity` is a smart data object which represents data such as a row or document in a
@@ -384,7 +385,7 @@ public function to($format, array $options = array()) {
case 'array':
$data = $this->_updated;
$rel = array_map(function($obj) { return $obj->data(); }, $this->_relationships);
- $data = array_merge($data, $rel);
+ $data = Set::merge($data, $rel);
$result = Collection::toArray($data, $options);
break;
default:
20 tests/cases/data/entity/DocumentTest.php
View
@@ -718,6 +718,26 @@ public function testIdGetDoesNotSet() {
$document->_id == "";
$this->assertFalse(array_key_exists('_id', $document->data()), $message);
}
+
+ /**
+ * Ensures that the data returned from the `data()` method matches the
+ * internal state of the object.
+ */
+ public function testEnsureArrayExportFidelity() {
+ $data = array(
+ 'department_3' => 0,
+ 4 => 0,
+ 5 => 0,
+ 6 => 0,
+ '6x' => 0,
+ 7 => 0,
+ 8 => 0,
+ 10 => 0,
+ 12 => 0
+ );
+ $doc = new Document(compact('data'));
+ $this->assertIdentical($data, $doc->data());
+ }
}
?>
Please sign in to comment.
Something went wrong with that request. Please try again.