Symfony ElasticaBundle query_builder_method

时间:2016-03-08 11:21:59

标签: php symfony doctrine-orm foselasticabundle

我需要上传具有状态批准的弹性Lead inly,这是我的,映射:

                 persistence:
                      driver: orm
                      model: Artel\ProfileBundle\Entity\Lead
                      provider:
                        query_builder_method: createIsActiveQueryBuilder
                      listener: ~
                      finder: ~

和我的query_builder_method:createIsActiveQueryBuilder:

public function createIsActiveQueryBuilder()
{
    $qb = $this->getEntityManager()->createQueryBuilder('d');

    $qb
        ->select('d')
        ->from('ArtelProfileBundle:Lead', 'd')
        ->where('d.statusLead = :status')
        ->setParameter('status', 'approved')
    ;

    return $qb;
}

但是当我跑步时

app/console fos:elastica:populate --no-reset

我在doc中读到

Your repository must implement this method and return a Doctrine query builder.

在我的数据库中,我有两个领导状态未获批准,当我更改一个以获得批准时,我有一个弹性导致。但是如果在DB中我没有获得状态批准的导致我一直有错误吗?

但有错误:

PHP Fatal error:  Wrong parameters for Exception([string $exception [, long $code [, Exception $previous = NULL]]]) in /home/ivan/host/aog-code/vendor/ruflin/elastica/lib/Elastica/Exception/ResponseException.php on line 34

 [Symfony\Component\Debug\Exception\FatalErrorException]                                                   
 Error: Wrong parameters for Exception([string $exception [, long $code [, Exception $previous = NULL]]]) 

当我创建具有默认状态的新潜在客户' not_approved'这个导致上传弹性,为什么我不明白听众上传这个导致,为什么不工作query_builder?

为什么不明白,我做错了什么?

1 个答案:

答案 0 :(得分:0)

该消息指出您应该返回QueryBuilder实例。致电:

$query = $qb->getQuery();
return $query;

您将从QueryBuilder

返回Query实例

您的功能应为:

public function createIsActiveQueryBuilder() {
  $qb = $this->getEntityManager()->createQueryBuilder('d');
  return $qb
    ->select('d')
    ->from('ArtelProfileBundle:Lead', 'd')
    ->where('d.statusLead = :status')
    ->setParameter('status', 'approved');
}