Skip to content
Permalink
Browse files

Initial implementation of fieldList in Marshaller::one()

  • Loading branch information...
lorenzo committed Jul 11, 2014
1 parent 22ed2f8 commit f62cad579811a6acc56cea5edd10976947786eb5
Showing with 31 additions and 1 deletion.
  1. +12 −1 src/ORM/Marshaller.php
  2. +19 −0 tests/TestCase/ORM/MarshallerTest.php
@@ -118,7 +118,18 @@ public function one(array $data, array $options = []) {
}
$properties[$key] = $value;
}
$entity->set($properties);
if (!isset($options['fieldList'])) {
$entity->set($properties);
return $entity;
}
foreach ((array)$options['fieldList'] as $field) {
if (isset($properties[$field])) {
$entity->set($field, $properties[$field]);
}
}
return $entity;
}
@@ -981,4 +981,23 @@ public function testMergeComplexType() {
$this->assertEquals('2014-02-14', $entity->created->format('Y-m-d'));
}
/**
* Tests that it is possible to pass a fieldList option to the marshaller
*
* @return void
*/
public function testOneWithFieldList() {
$data = [
'title' => 'My title',
'body' => 'My content',
'author_id' => 1
];
$marshall = new Marshaller($this->articles);
$result = $marshall->one($data, ['fieldList' => ['title', 'author_id']]);
$this->assertInstanceOf('Cake\ORM\Entity', $result);
unset($data['body']);
$this->assertEquals($data, $result->toArray());
}
}

0 comments on commit f62cad5

Please sign in to comment.
You can’t perform that action at this time.