title: What kind of issue may request a "cascade persist operation" for a Doctrine entity?
body: <p>I have a <strong>Like</strong> entity with a <strong>getDislike()</strong> function in my <em>Symfony2-Doctrine2</em> project. Once I retrieve a Like entity and I call the getDislike() function in an echo, nothing is printed. </p>
  
  <pre><code>echo '&lt;br /&gt;'. $like-&gt;getDislike(); //Nothing is printed (1, 0, true, false)
  echo '&lt;br /&gt;'. $like-&gt;getId(); // the entity id is printed
  </code></pre>
  
  <p>If I call the same function with the same entity in an if condition, </p>
  
  <pre><code>if($like-&gt;getDislike() == FALSE){ //throw an exception
  ....}
  </code></pre>
  
  <p>then the following error is returned:</p>
  
  <pre><code>A new entity was found through the relationship 'Acme\ArticleBundle\Entity\Article#likes' that
  was not configured to cascade persist operations for entity: Acme\ArticleBundle\Entity  
  \Like@00000000653f908100000000749fcbfe. Explicitly persist the new entity or configure cascading
  persist operations on the relationship. If you cannot find out which entity causes the problem
  implement 'Acme\ArticleBundle\Entity\Like#__toString()' to get a clue.
  </code></pre>
  
  <p>Why the preceding error happens! The Article entity is not mentioned in my code (of course there is a relationship many Like to one Article and vice versa in the doctrine scheme).</p>
  
  <p>Any idea?
  Upon request, I add the Like entity file:</p>
  
  <pre><code>namespace Acme\ArticleBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  use Doctrine\Common\Collections\ArrayCollection;
  
  
  /**
   * Acme\ArticleBundle\Entity\Like
   *
   * @ORM\Table()
   * @ORM\Entity
   */
  class Like
  {
  
  
  /**
   * @ORM\ManyToOne(targetEntity="Article")
   * @ORM\JoinColumn(name="article_id", referencedColumnName="id")
   */
  protected  $article;    
  
  
  /**
   * @ORM\Column(type="boolean")
   */
  protected  $dislike;      
  
  //.... other fields
  
  /**
   * Set dislike
   *
   * @param boolean $dislike
   */
  public function setDislike($dislike)
  {
      $this-&gt;dislike = $dislike;
  }
  
  /**
   * Get dislike
   *
   * @return boolean 
   */
  public function getDislike()
  {
      return $this-&gt;dislike;
  }
  
  //.... other methods
  </code></pre>
  
  <p>}</p>
  
  <p>Here is the article Entity:</p>
  
  <pre><code>namespace Acme\ArticleBundle\Entity;
  
  use Symfony\Component\Validator\Constraints as Assert;
  
  use Doctrine\ORM\Mapping as ORM;
  use Doctrine\Common\Collections\ArrayCollection;
  
  
  /**
   * Acme\ArticleBundle\Entity\Article
   *
   * 
   * @ORM\Table()
   * @ORM\Entity(repositoryClass="Acme\ArticleBundle\Repository\ArticleRepository")
   */
  class Article
  {
  
  /**
   *
   * @ORM\OneToMany(targetEntity="Like", mappedBy="article")
   */
  protected  $likes;    
  
  //.... other fields
  
  
  public function __construct() {
      ...
      $this-&gt;likes = new \Doctrine\Common\Collections\ArrayCollection();
      ...   
  }    
  
  
  }
  </code></pre>
  
  <p>And here is the controller code:</p>
  
  <pre><code> public function likeDislikeItemAction(){               
      if ($this-&gt;get('security.context')-&gt;isGranted('IS_AUTHENTICATED_FULLY')){
          $user = $this-&gt;get('security.context')-&gt;getToken()-&gt;getUser();
  
          $entityType = "AcmeArticleBundle:Article"; // This static for debugging
          $entityId = 1; // This static for debugging         
  
          $doctrine = $this-&gt;getDoctrine();
  
          $item = $doctrine
              -&gt;getRepository($entityType)
              -&gt;findOneById($entityId);
          if(is_object($item)){
             $itemlikes = $item-&gt;getLikes();
             $totvotes = sizeof($itemlikes);
             $numlikes = $this-&gt;getNumLikes($itemlikes);
             $numdislikes = $totvotes - $numlikes;
  
  
              $dislike_value = 'like'; // This static for debugging                
              if($dislike_value == 'like') $isDislike = FALSE;       
              else $isDislike = TRUE;
  
              $like =  $this-&gt;getLikeDislikeEntity($doctrine, $user, $entityType, $entityId);
  
              if(is_object($like)) { 
                $test = $like-&gt;getDislike();
                echo 'test val ' . $test;
              }
          }
         }
        return NULL;
       }
  
       private function getLikeDislikeEntity($doctrine, $user, $entityType, $entityId){
         if ($entityType == "AcmeArticleBundle:Article") {
          return $doctrine-&gt;getRepository("AcmeArticleBundle:Like")
                      -&gt;findOneBy(array('author' =&gt; $user-&gt;getId(), 'article' =&gt;$entityId));  
         }
         return null;
      }
  </code></pre>