Note that there are some explanatory texts on larger screens.

plurals
  1. POSymfony 2 - Doctrine - oneToMany : delete from many
    primarykey
    data
    text
    <p>I have two entities : Episode and Version. When I tried to delete a version a get an exception:</p> <blockquote> <p>Notice: Undefined index: episode in /var/www/Mendrock/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php line 1561 </p> </blockquote> <p>I already check relations but I didn't find the error.</p> <p>My entities: <strong>Episode</strong><br> <pre><code>namespace Mendrock\Bundle\SagaBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * Mendrock\Bundle\SagaBundle\Entity\Episode * * @ORM\Table(name="episode") * @ORM\Entity(repositoryClass="Mendrock\Bundle\SagaBundle\Repository\EpisodeRepository") */ class Episode { ... /** * * @ORM\OneToMany(targetEntity="Version", mappedBy="episode", cascade={"remove", "persist"}) */ private $versions; </code></pre> <p><strong>Version</strong> <pre><code>namespace Mendrock\Bundle\SagaBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Gedmo\Mapping\Annotation as Gedmo; /** * Mendrock\Bundle\SagaBundle\Entity\EpisodeVersion * * @ORM\Table(name="version") * @ORM\Entity(repositoryClass="Mendrock\Bundle\SagaBundle\Repository\EpisodeVersionRepository") */ class Version { ... /** * @ORM\ManyToOne(targetEntity="Episode", inversedBy="versions", cascade={"persist"}) * @ORM\JoinColumn(name="episode_id", referencedColumnName="id") */ private $episode; ... </code></pre> <p><strong>Controller</strong> </p> <pre><code> /** * * @Route("/versionConfirmeDelete/{id}", options={"expose"=true}) * @Method("GET") * @Template() */ public function versionConfirmeDeleteAction($id) { $em = $this-&gt;getDoctrine()-&gt;getManager(); $entity = $em-&gt;getRepository('MendrockSagaBundle:Version')-&gt;find($id); if (!$entity) { throw $this-&gt;createNotFoundException('Unable to find Version entity.'); } $deleteForm = $this-&gt;createDeleteForm($id); return array( 'entity' =&gt; $entity, 'delete_form' =&gt; $deleteForm-&gt;createView(), ); } /** * Deletes a Episode entity. * * @Route("/versionDelete/{id}") * @Method("POST") */ public function versionDeleteAction(Request $request, $id) { $form = $this-&gt;createDeleteForm($id); $form-&gt;bind($request); if ($form-&gt;isValid()) { $em = $this-&gt;getDoctrine()-&gt;getManager(); $entity = $em-&gt;getRepository('MendrockSagaBundle:Version')-&gt;find($id); $episode = $entity-&gt;getEpisode(); if (!$entity) { throw $this-&gt;createNotFoundException('Unable to find Version entity.'); } $em-&gt;remove($entity); $em-&gt;flush(); $this-&gt;get('session')-&gt;setFlash('success', 'La version "' . $entity . '" de l\'épisode "'.$episode.'" à été supprimé !'); } else { $this-&gt;get('session')-&gt;setFlash('error', 'Impossible de supprimer la version "' . $entity . '".'); } return $this-&gt;redirect($this-&gt;generateUrl('mendrock_saga_default_episodes')); } ################################################################# ### Commun ################################################## ################################################################# private function createDeleteForm($id) { return $this-&gt;createFormBuilder(array('id' =&gt; $id)) -&gt;add('id', 'hidden') -&gt;getForm() ; } </code></pre> <p>Any ideas of my problem?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload