Merge remote-tracking branch 'peerj/ObjectWithoutProperties' into serializer-integration

Conflicts:
	Transformer/ModelToElasticaAutoTransformer.php
This commit is contained in:
Damien Alexandre 2013-11-29 13:51:58 +01:00
commit e180f1fd61
3 changed files with 33 additions and 1 deletions

View file

@ -193,6 +193,8 @@ If you do this wrong, you will see a `RoutingMissingException` as elasticsearch
### Declaring `nested` or `object`
Note that object can autodetect properties
fos_elastica:
clients:
default: { host: localhost, port: 9200 }
@ -213,6 +215,12 @@ If you do this wrong, you will see a `RoutingMissingException` as elasticsearch
properties:
date: { boost: 5 }
content: ~
user:
type: "object"
approver:
type: "object"
properties:
date: { boost: 5 }
#### Doctrine ORM and `object` mappings

View file

@ -102,6 +102,11 @@ class POPO
);
}
public function getObj()
{
return array('foo' => 'foo', 'bar' => 'foo', 'id' => 1);
}
public function getUpper()
{
return (object) array('id' => 'parent', 'name' => 'a random name');
@ -272,6 +277,25 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase
), $data['sub']);
}
public function testObjectDoesNotRequireProperties()
{
$transformer = $this->getTransformer();
$document = $transformer->transform(new POPO(), array(
'obj' => array(
'type' => 'object'
)
));
$data = $document->getData();
$this->assertTrue(array_key_exists('obj', $data));
$this->assertInternalType('array', $data['obj']);
$this->assertEquals(array(
'foo' => 'foo',
'bar' => 'foo',
'id' => 1
), $data['obj']);
}
public function testParentMapping()
{
$transformer = $this->getTransformer();

View file

@ -71,7 +71,7 @@ class ModelToElasticaAutoTransformer implements ModelToElasticaTransformerInterf
$value = $this->propertyAccessor->getValue($object, $key);
if (isset($mapping['type']) && in_array($mapping['type'], array('nested', 'object'))) {
if (isset($mapping['type']) && in_array($mapping['type'], array('nested', 'object')) && isset($mapping['properties'])) {
/* $value is a nested document or object. Transform $value into
* an array of documents, respective the mapped properties.
*/