stwe / DatatablesBundle

This Bundle integrates the jQuery DataTables plugin into your Symfony application.
355 stars 236 forks source link

Doctrine Embeddable No longer supported? #948

Closed LauLaman closed 4 years ago

LauLaman commented 4 years ago

As for #393 support for Doctrine embeddables was introduces.

It looks like its no longer supported at version 1.0; the documentation doesn't mention it anywhere

My Setup

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table()
 */
class Organization
{
    /**
     * @ORM\Column(type="string")
     */
    private string $name;

    /**
     * @ORM\Embedded(class="Address")
     */
    private Address $postalAddress;
}
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Embeddable
 */
class Address
{
    /**
     * @ORM\Column(type="string")
     */
    private string $city;
}

The datatable:

class ListDatatable extends AbstractDatatable
{
    /**
     * @throws \Exception
     */
    public function buildDatatable(array $options = [])
    {
       /* ... */

        $this->columnBuilder
            ->add('id', Column::class, ['visible' => false])
            ->add('name', LinkColumn::class,    array(
                'title' => 'name',
                'empty_value' => '<span class="comment">none</span>',
                'route' => 'organization_view',
                'route_params' => function(array $row) {
                    return ['organizationid' => $row['id']];
                }
            ))
            ->add('postalAddress.city', Column::class, [
                'title' => 'city',
                'searchable' => true,
                'orderable' => true,
            ])
            ;
    }

    public function getEntity(): string
    {
        return Organization::class;
    }
}

This error will be thrown: \Doctrine\ORM\Query\QueryException

[Semantical Error] line 0, col 39 near 'postalAddress.city': Error: 'postalAddress' is not defined.
Package Version
sg/datatablesbundle 1.2.1
symfony 5.0.8
doctrine/orm 2.7.2
PHP 7.4.5
Seb33300 commented 4 years ago

Did you check the last comment of the link you posted? https://github.com/stwe/DatatablesBundle/pull/393#issuecomment-296384667

LauLaman commented 4 years ago

@Seb33300 Yes,

As I forgot to mention: Also adding 'dql' => 'postalAddress.city' to the options array will result in the same exception

Seb33300 commented 4 years ago

I think you should prefix it with the table alias as indicated in the doctrine documentation.

'dql' => 'organization.postalAddress.city'
LauLaman commented 4 years ago

@Seb33300 yes that works. That wasn't clear to me from the doctrine documentation.