omines / datatables-bundle

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

Iterating join queries won't work #262

Closed bertoost closed 2 years ago

bertoost commented 2 years ago

https://github.com/omines/datatables-bundle/blob/b51c5ac58b31973ea754b891de38dfe9e6624a74/src/Adapter/Doctrine/ORMAdapter.php#L183

I have created a custom adapter for my goal to support usage of the entity repository class of Doctrine. At the end I discovered that ->iterate() won't work for joined queries, since the result of a join-query can result in multiple of the root entities because of the joins. I ended up using this;

foreach ($query->getResult() as $result) {
    // ....
}
curry684 commented 2 years ago

Yes, this is expected behavior, once you start adding custom joins to your DQL we can no longer reliably predict the data being returned. You should in general implement such custom behavior in your application in that case, that is why adapters and such are easily extendable.