Skip to content

Commit

Permalink
BC Break: disable id indexation of subdocuments from a `Document::dat…
Browse files Browse the repository at this point in the history
…a()`.
  • Loading branch information
jails committed Jun 15, 2013
1 parent 4c32dbb commit aec7990
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
1 change: 1 addition & 0 deletions data/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ public function to($format, array $options = array()) {
$data = $this->_updated;
$rel = array_map(function($obj) { return $obj->data(); }, $this->_relationships);
$data = $rel + $data;
$options['indexed'] = isset($options['indexed']) ? $options['indexed'] : false;
$result = Collection::toArray($data, $options);
break;
case 'string':
Expand Down
39 changes: 38 additions & 1 deletion tests/cases/data/source/mongo_db/ExporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ public function testUpdatingMongoIdArray() {
}
}

public function testToData() {
public function testToDataOnDocumentSet() {
$data = array(
array(
'_id' => '4c8f86167675abfabd970300',
Expand Down Expand Up @@ -725,6 +725,43 @@ public function testToData() {
$this->assertEqual('Bar2', $accounts['4fb6e2df3e91581fe6e75739']['name']);
}

public function testToDataOnDocument() {
$data = array(
'_id' => '4c8f86167675abfabd970300',
'accounts' => array(
array(
'_id' => "4fb6e2dd3e91581fe6e75736",
'name' => 'Foo1'
),
array(
'_id' => "4fb6e2df3e91581fe6e75737",
'name' => 'Bar1'
)
)
);

$model = $this->_model;
$handlers = $this->_handlers;
$options = compact('model', 'handlers');
$schema = new Schema(array('fields' => $this->_schema));
$set = $schema->cast(null, null, $data, $options);

$result = $set->data();
$accounts = $result['accounts'];
$this->assertEqual('Foo1', $accounts[0]['name']);
$this->assertEqual('Bar1', $accounts[1]['name']);

$result = $set->to('array', array('indexed' => false));
$accounts = $result['accounts'];
$this->assertEqual('Foo1', $accounts[0]['name']);
$this->assertEqual('Bar1', $accounts[1]['name']);

$result = $set->to('array', array('indexed' => true));
$accounts = $result['accounts'];
$this->assertEqual('Foo1', $accounts['4fb6e2dd3e91581fe6e75736']['name']);
$this->assertEqual('Bar1', $accounts['4fb6e2df3e91581fe6e75737']['name']);
}

public function testIndexesOnExportingDocumentSet() {
$schema = new Schema(array('fields' => array(
'_id' => array('type' => 'id'),
Expand Down
6 changes: 3 additions & 3 deletions tests/fixture/model/gallery/export/testOneToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@
'created' => '2007-06-20 21:02:27',
'modified' => '2009-12-14 22:36:09',
'images' => array(
1 => array(
array(
'id' => '1',
'gallery_id' => '1',
'image' => 'someimage.png',
'title' => 'Amiga 1200',
'created' => '2011-05-22 10:43:13',
'modified' => '2012-11-30 18:38:10',
),
2 => array(
array(
'id' => '2',
'gallery_id' => '1',
'image' => 'image.jpg',
'title' => 'Srinivasa Ramanujan',
'created' => '2009-01-05 08:39:27',
'modified' => '2009-03-14 05:42:07',
),
3 => array(
array(
'id' => '3',
'gallery_id' => '1',
'image' => 'photo.jpg',
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/data/FieldsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function testFieldsWithJoins() {
'id' => $cId,
'name' => 'Celebrities',
'images' => array(
$eId => array(
array(
'id' => $eId,
'title' => 'John Doe'
)
Expand Down

0 comments on commit aec7990

Please sign in to comment.