PropertyAccessor requires a graph of objects or arrays to operate on, but it found type "NULL"

Viewed 7614

I have this method in AssignmentTypeAdmin:

protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->add('code', 'text')
            ->add('label', 'text', array('label'=>'Libellé'))
            ->add('assignHierarchyNode.label', 'text', array('label' => 'Noeud hiérarchique'))
            ->add('assignPortfolioType.portfolioTypeLabel', null, array('label' => 'Type de portefeuille'))
            ->add('assignGeoHierarchyNodeType.label', null, array('label' => 'Type de noeud hiérarchique'));
    }

In AssignmentType class:

/**
 * @ORM\ManyToOne(targetEntity="HierarchyManagerBundle\Entity\HierarchyNode")
 * @ORM\JoinColumn(name="assign_hierarchy_node_id", referencedColumnName="id", nullable=FALSE)
 */
private $assignHierarchyNode;

In HierarchyNode class: ...

 /**
     * @var string
     * @Gedmo\TreePathSource
     * @ORM\Column(name="label", type="string", length=255)
     */
    private $label;

... also get and set methods.

My problem is I get this error and I don't have any idea why:

PropertyAccessor requires a graph of objects or arrays to operate on, but it found type "NULL" while trying to traverse path "assignHierarchyNode.label" at property "label".

I use Symfony 3.1, Doctrine 2.5.2, Sonata Bundle for this. Thank you in advance!

2 Answers

For me, it worked when i initialized it as an array or ArrayCollection.

public function __construct() {
   $this->conditions = [];
}

Symfony throws the exception because, if not initialized, it cannot iterate on it.

Related