Properities should not be required for object as elastica can automap
This commit is contained in:
parent
814460dbf2
commit
fab42fa0ce
3 changed files with 33 additions and 1 deletions
|
|
@ -184,6 +184,8 @@ per type.
|
|||
|
||||
### Declaring `nested` or `object`
|
||||
|
||||
Note that object can autodetect properties
|
||||
|
||||
fos_elastica:
|
||||
clients:
|
||||
default: { host: localhost, port: 9200 }
|
||||
|
|
@ -204,6 +206,12 @@ per type.
|
|||
properties:
|
||||
date: { boost: 5 }
|
||||
content: ~
|
||||
user:
|
||||
type: "object"
|
||||
approver:
|
||||
type: "object"
|
||||
properties:
|
||||
date: { boost: 5 }
|
||||
|
||||
### Populate the types
|
||||
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
@ -268,6 +273,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();
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ class ModelToElasticaAutoTransformer implements ModelToElasticaTransformerInterf
|
|||
continue;
|
||||
}
|
||||
|
||||
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.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue