graphaware / neo4j-php-ogm

Neo4j Object Graph Mapper for PHP
MIT License
153 stars 55 forks source link

Call to a member function isCollection() on null #140

Closed marius-dev closed 7 years ago

marius-dev commented 7 years ago

I'm trying to serialize a collection of objects taken from db and get the following error:

Call to a member function isCollection() on null

on vendor/graphaware/neo4j-php-ogm/src/Hydrator/EntityHydrator.php", "line": 81,

Each object is made up of several objects and object collections. What could be the problem?

oliver-schulz commented 7 years ago

Did you add $this->property = new Collection(); to your __constructor? You have to initialize your properties first.

marius-dev commented 7 years ago

I'm pretty sure I've initialized all the collections. The problem arises on ManuToMany relationships, where each entity contains a collection of the other entity type. To avoid "circular reference problem" at serialization I create a normalizer like tihis:

class Normalizer extends ObjectNormalizer { public function __construct(ClassMetadataFactoryInterface $classMetadataFactory = null, NameConverterInterface $nameConverter = null, PropertyAccessorInterface $propertyAccessor = null, PropertyTypeExtractorInterface $propertyTypeExtractor = null) { parent::__construct($classMetadataFactory, $nameConverter, $propertyAccessor, $propertyTypeExtractor); $this->setCircularReferenceHandler(function ($object) { return $object->getId(); }); } }

After one layer, this Normalizer replece the reference to it's id.

I don;t know it that is the problem.

ikwattro commented 7 years ago

would you be able to provide a link to a test ?