DoctrineBehaviors icon indicating copy to clipboard operation
DoctrineBehaviors copied to clipboard

Tree Behavior

Open celsoandrade opened this issue 2 years ago • 1 comments

I'm trying to get doctrine tree behavior and I couldn't get it to work.

Here is my entity file (some is hidden to better reading)

` use Knp\DoctrineBehaviors\Contract\Entity\TreeNodeInterface; use Knp\DoctrineBehaviors\Model\Tree\TreeNodeTrait; ...

#[ORM\Entity(repositoryClass: UnidadeRepository::class)] class Unidade implements BlameableInterface, TimestampableInterface, LoggableInterface, TreeNodeInterface { // Hook timestampable behavior use TimestampableTrait;

// Hook blameable behavior
use BlameableTrait;

// Hook loggable behavior
use LoggableTrait;

// Hook tree behavior
use TreeNodeTrait;

... `

I can't add a root node that's the error I'm facing.

image

Then I add a root node by hand like this image

Then when I try to add a child node I get this error

image

I've look to source code I found out that I need an ID for entity but how can I have an ID if I'm creating the record?

` $pai = $unidadeRepository->findOneById(1);

$unidadeFilho = new Unidade(); $unidadeFilho->setCodigoUnidadeDgp('B234B'); $unidadeFilho->setTipo(1); $unidadeFilho->setStatus(Unidade::STATUS_ATIVO); $unidadeFilho->setDescricao('Filho 1'); $unidadeFilho->setChildNodeOf($pai); `

Thank you for any help.

Celso Andrade

celsoandrade avatar Jan 10 '23 18:01 celsoandrade

just an update. when I've comment out these lines: image

and alter materialized_path to accept null everything works and got my database populated

image

celsoandrade avatar Jan 11 '23 15:01 celsoandrade