omines / datatables-bundle

DataTables bundle for Symfony
https://omines.github.io/datatables-bundle/
MIT License
258 stars 115 forks source link

Subquery to add oneToMany information #95

Closed zicheee closed 4 years ago

zicheee commented 5 years ago

Hi,

I am trying to add a column to my table that is calculated (select count ...) I have a table address and other tables that have a ManyToOne relation to the address table.

In my AddressRepository the query looks like this:

return $this->createQueryBuilder('a')
                  ->select('a.street', 'a.zip', 'a.city')
                  ->addSelect('(
                        SELECT count(t.id) FROM App\Entity\Table01 t
                        WHERE t.address = a.id
                      ) as tCount')
                  ->getQuery()
                  ->getResult();

and I am able to receive an array as output with exact 4 columns.

I tried to put this to the ORMAdapater to use the datatables logic for ordering, pagination etc. but I was not able to do it. Within the documentation I couldn't find something to achieve my goal.

If someone could give me just a hint I would also be happy to enhance the documentation for this.

My current solution is to use the ArrayAdapter and parse the request with my own logic. This solution is definetly not what I want.

Best regards Michael

curry684 commented 4 years ago

Please refer to https://github.com/omines/datatables-bundle/issues/161 and #121