omines / datatables-bundle

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

Issues with Doctrine Embeddables #86

Closed beezischillin closed 4 years ago

beezischillin commented 5 years ago

Hi peeps!

I've been having issue with getting Doctrine Embeddables to work with the DataTables.

If I have an entity that has its address fields in an Address class

    /**
     * @ORM\Embedded(class="App\Entity\Embedded\Address", columnPrefix="address_")
     * @Assert\Valid()
     */
    private $address;

With the address class simply containing fields that describe an address

/** @ORM\Embeddable() */
class Address
{
    /**
     * @ORM\Column(type="string", nullable=true)
     */
    private $address;
    /**
     * @ORM\Column(type="string", nullable=true)
     */
    private $street;
    /**
     * @ORM\Column(type="string", nullable=true)
     */
    private $city;
    /**
     * @ORM\Column(type="string", nullable=true)
     */
    private $state;
    /**
     * @ORM\Column(type="string", nullable=true)
     */
    private $zipCode;

I'm having difficulties using this in a Table. I've tried to use 'field' => 'address.city', which results in an exception:

Association name expected, 'address' is not an association.

Using 'propertyPath' => 'address.city' works insofar as it doesn't throw an error but using 'orderField' => 'address.city' in conjunction with this causes the following exception:

[Semantical Error] line 0, col 154 near 'address.city': Error: 'address' is not defined.

Thank you!

curry684 commented 5 years ago

Mmmmmm yes I'm pretty sure this can blow up in a lot of places, and will not be easy to fix. This'll need thorough investigation.

curry684 commented 5 years ago

https://github.com/omines/datatables-bundle/blob/master/src/Adapter/Doctrine/ORMAdapter.php#L283-L305 is likely too naive for this.

Clorr commented 4 years ago

Hi, I used today an entity with embeddables, and I came to the same problem @beezischillin encountered. I fixed it the same way he did by using propertyPath instead of field. Maybe the main difference is I use FetchJoinORMAdapter.

For now, I'm not blocked, so it's mostly FYI. I would love to investigate on that, but I checked the code, and it's way above my skills on doctrine/symfony for now ;-)