title: Doctrine2 / Zend1
body: <p>I have an application written in Zend 1/Doctrine2 (2.1.5). It is important to note several important points of the application:</p>
  
  <ul>
  <li>I have an entity "group" what can possess several types:
  <ul>
  <li>manual group</li>
  <li>pending group</li>
  <li>validate groupe</li>
  </ul></li>
  <li>For every different type corresponds a class group inheriting from an    abstracted class mother</li>
  <li>My groups are trained to have a tree (graph theory).</li>
  <li>I shall have to have type ManyToMany's relation and thus intermediate table SQL.
      However, I need to have attributes specific in this relation.
      So, I have to create a disguised relation ManyToMany: I have to create myself this intermediate. It's name is "Composition".</li>
  <li>For the type "pending group", as its name indicates it, a user owes validated this group so that it is actual.
      A group passes automatically awaiting validation if it consists of at least 5 groups.</li>
  <li>If a group is awaiting validation it can be thus being is accepted or refused.</li>
  <li>If a group awaiting validation is then refused it returns to its version previous, if it exists.</li>
  <li>If a group awaiting validation is to accept, it becomes actual and can be used.</li>
  </ul>
  
  <p>Here is my problem, when that a group becomes awaiting validation further to an addition of group, for example, the application does not preserve the old version of the group.
  Indeed, the addition of this new group is allocated on one hand to the group awaiting validation but also to the group of previous type.</p>
  
  <h2>Here is my code:</h2>
  
  <pre><code>    public function putAction() {
          //it's not a pending group.
          $pendingGroup = $this-&gt;toPendingGroup($object);
          $this-&gt;em-&gt;persist($pendingGroup);
          $this-&gt;em-&gt;flush();
          // send mail
      }
  
      public function toPendingGroup($groupToValidate)
      {
          $newGroup = new Model_Group_Manual_Pending();
          $oldGroup = Serializer_Arrays::serialize($groupToValidate);
          unset($oldGroup['components']);
          Serializer_Arrays::unserialize($oldGroup, 'Model_Group_Manual_Pending', $newGroup);
          $newGroup-&gt;setSupport(Gromit_Di::getAcl()-&gt;getAuthUser());
          $compositions = array();
          foreach ($groupToValidate-&gt;getComponents() as $composition)
          {
              if  ($composition-&gt;getId() == NULL) {
                  $newComposition = new Model_Composition();
                  // Initialisation de ma composition
                  $compositions[] = $newComposition;
              }
          }
          $newGroup-&gt;setComponents($compositions);
          return $newGroup;
      }
  ---
  </code></pre>
  
  <p>To summarize it, here is a plan of the situation:
  <a href="http://postimg.org/image/7uaep5gnl/" rel="nofollow">example</a>
   - In black the version previous
   - In red the new version
   - In blue the not deliberate connection</p>
  
  <p>Thank you for your help</p>