Skip to content

Commit b4c01f3

Browse files
committed
Merge branch 'formapro-forks/fixing-bug-with-parent' into 3.0.x
2 parents 2ce2d7e + 659468a commit b4c01f3

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

DependencyInjection/FOSElasticaExtension.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,13 @@ private function loadObjectPersister(array $typeConfig, Reference $typeRef, Cont
393393
$arguments[] = array(new Reference($callbackId), 'serialize');
394394
} else {
395395
$abstractId = 'fos_elastica.object_persister';
396-
$arguments[] = $this->indexConfigs[$indexName]['types'][$typeName]['mapping']['properties'];
396+
$mapping = $this->indexConfigs[$indexName]['types'][$typeName]['mapping'];
397+
$argument = $mapping['properties'];
398+
if(isset($mapping['_parent'])){
399+
$argument['_parent'] = $mapping['_parent'];
400+
}
401+
$arguments[] = $argument;
402+
397403
}
398404

399405
$serviceId = sprintf('fos_elastica.object_persister.%s.%s', $indexName, $typeName);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
4+
namespace FOS\ElasticaBundle\Tests\Functional\DependencyInjection;
5+
6+
7+
use FOS\ElasticaBundle\DependencyInjection\FOSElasticaExtension;
8+
use Symfony\Component\DependencyInjection\ContainerBuilder;
9+
use Symfony\Component\Yaml\Yaml;
10+
11+
class FOSElasticaExtensionTest extends \PHPUnit_Framework_TestCase
12+
{
13+
14+
/**
15+
* @test
16+
*/
17+
public function shouldAddParentParamToObjectPersisterCall()
18+
{
19+
20+
$config = Yaml::parse(file_get_contents(__DIR__.'/config/config.yml'));
21+
22+
$containerBuilder = new ContainerBuilder;
23+
$containerBuilder->setParameter('kernel.debug', true);
24+
25+
$extension = new FOSElasticaExtension;
26+
27+
$extension->load($config, $containerBuilder);
28+
29+
$this->assertTrue($containerBuilder->hasDefinition('fos_elastica.object_persister.test_index.child_field'));
30+
31+
$persisterCallDefinition = $containerBuilder->getDefinition('fos_elastica.object_persister.test_index.child_field');
32+
33+
$arguments = $persisterCallDefinition->getArguments();
34+
$arguments = $arguments['index_3'];
35+
36+
$this->assertArrayHasKey('_parent', $arguments);
37+
$this->assertEquals('parent_field', $arguments['_parent']['type']);
38+
}
39+
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
fos_elastica:
2+
clients:
3+
default:
4+
url: http://localhost:9200
5+
indexes:
6+
test_index:
7+
client: default
8+
types:
9+
parent_field:
10+
mappings:
11+
text: ~
12+
persistence:
13+
driver: orm
14+
model: foo_model
15+
child_field:
16+
mappings:
17+
text: ~
18+
persistence:
19+
driver: orm
20+
model: foo_model
21+
_parent: { type: "parent_field", property: "parent" }

0 commit comments

Comments
 (0)