为什么我有空嵌套实体?我有指数天赋。在数据库中,人才有嵌套用户,当我更新或创建人才时,它不会被更新为ElasticSearch中的嵌套对象,我不明白为什么?
fos_elastica:
clients:
default:
host: %elastica_host%
port: %elastica_port%
headers: { Authorization: Basic %elastica_auth_header% }
indexes:
profile:
finder: ~
types:
talent:
mappings:
id:
type: integer
slug:
type: string
description:
type: string
user:
type: "nested"
properties:
id: ~
username:
type: string
我搜索并查找覆盖侦听器postPersist
,postUpdate
和preRemove
fos_elastica.listener.talent:
class: Artel\SiteBundle\EventListener\ElasticaCourseListener
arguments:
- @fos_elastica.object_persister.user.user
- ['postPersist', 'postUpdate', 'preRemove']
- @fos_elastica.indexable
calls:
- [ setContainer, ['@service_container', @fos_elastica.object_persister.profile.talent ] ]
tags:
- { name: 'doctrine.event_subscriber' }
我自己的听众Artel\SiteBundle\EventListener\ElasticaCourseListener
看起来像这样:
<?php
namespace Artel\SiteBundle\EventListener;
use Doctrine\Common\EventArgs;
use FOS\ElasticaBundle\Doctrine\Listener as BaseListener;
use FOS\ElasticaBundle\Persister\ObjectPersister;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Artel\ProfileBundle\Entity\Developer;
class ElasticaCourseListener extends BaseListener
{
private $container;
private $objectPersisterSession;
public function setContainer(ContainerInterface $container, ObjectPersister $objectPersisterSession)
{
$this->container = $container;
$this->objectPersisterSession = $objectPersisterSession;
}
public function postUpdate(EventArgs $args)
{
$entity = $args->getEntity();
if ($entity instanceof Developer) {
$this->scheduledForUpdate[] = $entity;
foreach ($entity->getUser() as $session) {
$this->objectPersisterSession->replaceOne($session);
}
}
}
}
现在,我有错误
[Symfony的\元器件\调试\异常\ ContextErrorException]
运行时注意:Artel \ SiteBundle \ EventListener \ ElasticaCourseListener :: postUpdate()声明应与FOS \ ElasticaBundle \ Doctrine \ Listener :: postUpdate(Doctrine \ Common \ Persistence \ Event \ LifecycleEventArgs $ eventArgs)兼容
请帮助
答案 0 :(得分:0)
你必须使用它:
the Ukelele
the Guitar
Lebanon
忘了那个:
use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
Doctrine中有一些更新;)