AliDatatableBundle icon indicating copy to clipboard operation
AliDatatableBundle copied to clipboard

FOSUserBundle incompatibility, Properties XXXX does not exist

Open IvanCou opened this issue 9 years ago • 1 comments

After 3 days working arround this problem there is some informations that could be useful for people in the same configuration.

I had the error "Properties XXXX does not exist" when I try to display datatable for some entities only.

In fact the problem occur only if there is a relation between the entity you want to display and a FosUser entity, even if you don't display any field of the user entity.

And the problem occur Only if the connected user is related with one of entities. If your connected user is not related to company entity (for exemple) all is working perfect, as soon as you add the connected user to one company, you ar not able to display datatable and you get the message "Properties XXXX does not exist" .

it's look like there is a incompatibility with the proxy.objects used by FOSUserBundle et AliDatatble in DoctrineBuilder.php

there is my actual composer version, I have already try with the latest ones with the same results "friendsofsymfony/user-bundle": "v2.0.0-alpha3", "ali/datatable": "2.1.0",

IvanCou avatar Nov 23 '16 10:11 IvanCou

There is the solution if it can help 👍

in fact the Doctrine builder don't manage correctly the proxy Objects and the reflectionClass. If you try to use ReflexionClass on a proxy object you are not able to get proporties of the main object. so there is a way to make it works by retreiving the real class of a proxyobject before get his properies

if (isset($object)){ $ref_class = new \ReflectionClass($object); if (property_exists($ref_class, $prop) or property_exists($object,$prop) ){ $property = $ref_class->getProperty($prop);
$property->setAccessible(true); return $property->getValue($object); } else { $realClass = \Doctrine\Common\Util\ClassUtils::getRealClass(get_class($object)); $property = (new \ReflectionClass($realClass))->getProperty($prop); $property->setAccessible(true); return $property->getValue($object); } }

IvanCou avatar Nov 30 '16 09:11 IvanCou