waldo2188 / DatatableBundle

Symfony2 Ajax Datatable Bundle to simplify the use of http://datatables.net/ (and Doctrine entity inside)
MIT License
17 stars 16 forks source link

Setting custom entityManger #8

Closed MlleDelphine closed 7 years ago

MlleDelphine commented 8 years ago

I had to switch from AliDatabundle to another which is compatible with Symfony 3.

Unfortunatly, and don't understand why, customizing "entityManager" has not be forked here.. Why that ?

I have several entityManagers and, obviously, the one I have to use for my DataTable is not the one set by default.

Is this a missing ? Does it exist another way (in config.yml for example) to set which entityManger using ?

MlleDelphine commented 8 years ago

Ok, I found a solution to do that but I keep thinking that "setEntityManager" should be integrated.

My solution, for others :

  $em = $this->getDoctrine()->getManager("custom_maanger");
  $dataT = $this->get('datatable');
   $queryBuilder = new QueryBuilder($em);
   $doctrineQueryBuilder = new DoctrineBuilder($em, $this->get('request_stack'));
   $doctrineQueryBuilder->setDoctrineQueryBuilder($queryBuilder);

 return $dataT
            ->setEntity("APIBundle:FSProject", "p") 
            ->setFields(
                array(
                    "_identifier_"  => 'p.trackingNumber')
            );