4

I'm getting the above error when performing a search in a Symfony2 CRM I've been working on. According to Google searches it seems this is an issue relating to the KNP Paginator bundle, but I cannot seem to find a solid solution.

In this instance, I am using data from an OpenCart database, and I need to be able to search by Postcode and Company name, both of which exist in the address table which is joined via a mapped value within the Customer entity, defaultaddress.

To this end, I've had to write a custom query in a function called findCustomerByPostcode like so:

$this->getEntityManager()
    ->createQuery('SELECT c FROM AppBundle:Oc49Customer c JOIN AppBundle:Oc49Address a WITH c.defaultaddress = a.id WHERE a.postcode LIKE :postcode')
    ->setParameter('postcode','%'.$postcode.'%')
    ->getResult();

However, when I perform a search on postcode, I get the following error in the browser:

One of listeners must count and slice given target

which refers to the Paginator.php file within the KNP bundle. I have updated to the most recent version, 2.5 yet I cannot seem to shake this error, and to me it does not even make sense.

Any help is much appreciated, as I cannot think of another way of search via a value within a joined table.

Which returns results from the postcode search, and then in the Controller:

$customers = $customer_repository->findCustomerByPostcode($filter_value);

$paginator = $this->get('knp_paginator');
  $pagination = $paginator->paginate(
    $customers,
    $request->query->get('page', 1),
    20
);
Michael Emerson
  • 1,774
  • 4
  • 31
  • 71

1 Answers1

0

You can use the queryBuilder with the left join

public function findCustomerByPostcode($postcode) {
    $query = $this->entityManager->createQueryBuilder();
    $query
        ->select('c', 'a')
        ->from('AppBundle:Customer', 'c')
        ->leftJoin('c.address', 'a')
        ->setParameter('postcode', $postcode)

    return $query->getQuery()->getResult();
}
Moni
  • 31
  • 3