DoctrineBehaviors
DoctrineBehaviors copied to clipboard
Tree Behavior
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.
Then I add a root node by hand like this
Then when I try to add a child node I get this error
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
just an update.
when I've comment out these lines:
and alter materialized_path to accept null everything works and got my database populated