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

Setting parent document to a Generic Node created on-the-fly in a prePersist listener causes PHPCRException #653

Open
kminh opened this issue Jul 24, 2015 · 3 comments

Comments

@kminh
Copy link

kminh commented Jul 24, 2015

Hello,

I'm trying to "move" a new (yes a new) document (Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\Route) to another node by using setParentDocument in a prePersist event listener.

The target node is created on the fly if it's not there, using NodeHelper::createPath (I only need a generic target node).

    public function prePersist(LifecycleEventArgs $args)
    {
        $route = $args->getObject();
        $dm = $args->getObjectManager();

        if ($route instanceof Route) {
            $localeNodePath = $this->routeRoot . '/' . $this->locale;

            if (!$localeNode = $dm->find(null, $localeNodePath)) {
                $session = $dm->getPhpcrSession();
                $localeNode = NodeHelper::createPath($session, $localeNodePath);

                /* $session->save(); I believe this is not needed? */ 
            }

            $route->setParentDocument($localeNode);
        }
    }

The exception message is Document is not managed and has no id ....

Perhaps this is caused by the fact that the target node is created on the fly, but even calling $session->save doesn't help.

Any insight is greatly appreciated.

@lsmith77
Copy link
Member

can you try and create a test case for this?

@kminh
Copy link
Author

kminh commented Jul 26, 2015

Hmm not sure where I should place the test? Here perhaps?

https://github.com/doctrine/phpcr-odm/tree/master/tests/Doctrine/Tests/ODM/PHPCR

I don't know anything about PHPCR ODM's internals so I'm not sure if I can create something useful.

@lsmith77
Copy link
Member

have a look at some of the event tests here for inspiration https://github.com/doctrine/phpcr-odm/tree/master/tests/Doctrine/Tests/ODM/PHPCR/Functional

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