I try to realize such a effect in a form of creating a new category : I add a ‘select list’ to the form to show all the category i have created ,so I tried:
> /**
> * @var string $parent
> *
> * @ORM\ManyToOne(targetEntity="ProductCategory")
> * @ORM\JoinColumn(name="product_category_id",
> referencedColumnName="id")
> */
>
> private $parent;
then i want to realize that:if the checkbox isRoot is selected ,the parent option is set “root”,so i wrote:
> if($entity->getIsRoot()){
> $entity ->setParent('root');
> }
However,it give me a exception:
Expected argument of type “object”, “string” given
what’s the matter? How to solve the problem.
Thanks in advance! 🙂
Looks like your problem is that the
expects an object of type Category.
Since you don’t want to select a parent category for root nodes, you should not set the parent.