3

I have problem with changing parent of document inside sonata admin.

My document has property like this:

 /**
 * @PHPCRODM\Children(filter="teaserimage*", cascade="persist")
 * @var Image[]
 */
protected $teaserImages;
....
/**
 * @Validation\PhpcrImage(maxWidth="1500", maxHeight="844", minWidth="600", minHeight="338", minRatio="1.77", maxRatio="1.78", nullable=false)
 *
 * @return Image|null
 */
public function getTeaserImage()
{
   return $this->getLocalizedImage($this->teaserImages, 'teaserimage');
}

/**
 * @param Image $image
 */
public function setTeaserImage($image)
{
    $this->teaserImages->add(
        self::setupImage($image, $this->getLocalizedImageNodeName('teaserimage'), $this->getTeaserImage())
    );
}

When i tried to change parent of any article document i got error like

The server returned a "500 Internal Server Error".

The Id is immutable (/cms/content/blog/blog-post-for-12th-october/teaserimage_de.jpg !== /cms/content/blog/blog-post-for-12th-october). Please use DocumentManager::move to move the document: blog post for 12th October (/cms/content/blog/blog-post-for-12th-october)

Although this error occurs, my document has been moved to the right place with all subdocument.

this is how my document looks like https://gist.github.com/milosnovi/a83f400c8ff06b4de6dd96e1f149a8dd

Milos
  • 543
  • 8
  • 15
  • did you try to use the move() function of the document manager? can you try to find out what sonata admin is doing when you move in the gui, is it using something else than the move function? – dbu Nov 02 '16 at 14:21

1 Answers1

0

Check your preUpdated, prePersists methods. You shouldn't flush object in these methods while the change is a parent change.