Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tree] Inserting without parent #597

Closed
phpSimplex opened this issue Sep 19, 2020 · 1 comment
Closed

[Tree] Inserting without parent #597

phpSimplex opened this issue Sep 19, 2020 · 1 comment

Comments

@phpSimplex
Copy link

phpSimplex commented Sep 19, 2020

When there is no parent, the "MaterializedPath" will be stored as a /.
If you call the $entity->getFlatTreeQB() the sorting is based on the MaterializedPath.
the sorting is not right becouse the entitys with no parent will be first in line.

If there is no parent it should be stored as /{id} to create a right sorting on the MaterializedPath.
My workaround;

/**
* @Orm\PostPersist()
* @Orm\PostUpdate()
*/
public function postInsert(LifecycleEventArgs $event): void
{
// set parent child relation path
$em = $event->getEntityManager();
if (null !== ($parent = $this->getParent())) {
$child = $this;
$child->setMaterializedPath($parent->getParentMaterializedPath() . '/'.$child->getId());
$em->persist($child);
$em->persist($parent);
} else {
$this->setMaterializedPath('/' . $this->getId());
}
$em->flush();
}

@TomasVotruba
Copy link
Contributor

Hi, I'm going through old opended issues and PRs to cleanup too-long-opened items and close them. Thank you for your contribution and time.

We needs a feature with test and passing CI to be able to merge it without letting a bug in.
If this is still relevant for you, please add code with test and make CI pass first. Then we'll able to merge your feature without further waiting 👍

Thank for understanding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants