omines / datatables-bundle

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

innerJoin not working, throwing not allowed #93

Closed timo002 closed 4 years ago

timo002 commented 5 years ago

I need to do a simple join to populate the datatables table. If I would write a query in my repository, I would write this:

public function findAllBySupplier($supplierId)
    {
        return $this->createQueryBuilder('t')
            ->innerJoin('t.stocks', 's')
            ->andWhere('t.isDeleted = 0')
            ->andWhere('s.supplier = :supplier_id')
            ->setParameter('supplier_id', $supplierId)
            ->getQuery()
            ->getResult();
    }

Doing this in the custom query part, it fails on Iterate with fetch join in class App\Entity\Stock using association tyre not allowed. Probably the same issue as in this open issue: https://github.com/omines/datatables-bundle/issues/30

I understand that the join might result in multiple rows, but I don't care about it. And if I would, I could allways use a group by. How would I be able to get this working, I need the join on s.supplier_id.

Tyre.stocks is OneToMany relation

@ORM\OneToMany(targetEntity="App\Entity\Stock", mappedBy="tyre")
curry684 commented 5 years ago

I understand that the join might result in multiple rows, but I don't care about it.

But that is the point why it's not allowed by default, it's an open invitation to get weird bugs and crashes. I think best route here would be to provide a custom adapter implementation providing the necessary transformations.

A demonstration of what you can achieve can be found in the tests at https://github.com/omines/datatables-bundle/blob/master/tests/Fixtures/AppBundle/DataTable/Adapter/CustomORMAdapter.php