omines / datatables-bundle

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

Entity with name "Order" goes wrong #209

Closed tomfischerNL closed 3 years ago

tomfischerNL commented 3 years ago

Using Symfony version 5.2.1

I have multiple Entities: User, Account, OrderItem and Order.

When I use the following code, it works: $table = $dataTableFactory->create() ->add('id', TextColumn::class) ->createAdapter(ORMAdapter::class, [ 'entity' => User::class ]) ->handleRequest($request);

But when I use the Order entity, it fails (500 error)

$table = $dataTableFactory->create() ->add('id', TextColumn::class) ->createAdapter(ORMAdapter::class, [ 'entity' => Order::class ]) ->handleRequest($request);

Every entity I use works, except the Order entity. Has this something to do with the fact that the name "order" is ambiguous, because it is also a "order" term, for sorting.

Thanks in advance,

maxhelias commented 3 years ago

Can you provide the error stack that is in the profiler ?

I had a similar case because doctrine had transformed the query alias into a reserved word for my DBMS. I worked around the problem with a query in my datatable to define the alias myself.

tomfischerNL commented 3 years ago

Hi Maxhelias,

This is the stack trace: Schermafbeelding 2021-01-18 om 10 48 00

Schermafbeelding 2021-01-18 om 10 48 43

maxhelias commented 3 years ago

I think it's the same case as me because the word "order" must be interpreted as "order by" in sql. Try something like this :

->createAdapter(ORMAdapter::class, [
    'entity' => Order::class,
    'query' => static function (QueryBuilder $builder): void {
        $builder
            ->select('o')
            ->from(Order::class, 'o')
        ;
    },
])
curry684 commented 3 years ago

This is a Doctrine issue, not related specifically to this bundle.

In general, try not to have entities called select, insert, order, where or other SQL-reserved words. It gets messy 😉