Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-422

Unable to add entity in @ManyToMany association when owning entity is extended from another entity

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Blocker Blocker
    • Resolution: Fixed
    • Affects Version/s: 2.0-ALPHA4
    • Fix Version/s: 2.0-BETA1
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      PHP 5.3.2

      Description

      Dear developers,

      I'm not sure if i extend entities in right way but i found different behaviour in extended entity which won't process add in @ManyToMany association.
      My class are defined like this:

      /**
       * @Entity
       * @HasLifecycleCallbacks
       * @InheritanceType("JOINED")
       * @DiscriminatorColumn(name="discr", type="string")
       * @DiscriminatorMap({"guest" = "Shop_Data_Entity_Guest", "customer" = "Shop_Data_Entity_Customer"})
       */
      class Shop_Data_Entity_Guest extends Shop_Data_Entity_Abstract {
          public function __construct() {
              /* call parent construct with all parameters */
              call_user_func_array(array("parent","__construct"),func_get_args());
          }
      }
      
      /**
       * @Entity
       * @HasLifecycleCallbacks
       */
      class Shop_Data_Entity_Customer extends Shop_Data_Entity_Guest {
          /**
           * @ManyToMany(targetEntity="Shop_Data_Entity_Contact", cascade={"persist","remove"} )
           * @JoinTable(name="Shop_Data_Entity_Customer__homes",
           *      joinColumns={@JoinColumn(name="customer_id", referencedColumnName="id", onDelete="cascade" )},
           *      inverseJoinColumns={@JoinColumn(name="contact_id", referencedColumnName="id", onDelete="cascade" )}
           *      )
           */
          public $homes;
      
          public function __construct() {
              /* call parent construct with all parameters */
              call_user_func_array(array("parent","__construct"),func_get_args());
      
              $this->homes = new Shop_Data_Collection_Standard(); // this class only extends ArrayCollection
          }
      }
      

      When i fire this code:

              $q = $em->createQuery("select c from Shop_Data_Entity_Customer c");
              $q->setMaxResults(1);
              $customers = $q->getResult();
              
              $contact = new Shop_Data_Entity_Contact();
              $customers[0]->home->add($contact);
              $em->flush();
      

      There's no change in database.
      When i change definition od Guest class like this:

      /** @MappedSuperclass */
      class Shop_Data_Entity_Guest extends Shop_Data_Entity_Abstract {
          public function __construct() {
              /* call parent construct with all parameters */
              call_user_func_array(array("parent","__construct"),func_get_args());
          }
      }
      

      It start work and every firing of my code add one contact and association to my database. It causes problem only when owning entity is quered from database at first.

        Activity

        Ondrej Sibrina created issue -
        Ondrej Sibrina made changes -
        Field Original Value New Value
        Attachment DDC406Test.php [ 10482 ]
        Ondrej Sibrina made changes -
        Priority Major [ 3 ] Blocker [ 1 ]
        Roman S. Borschel made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        Roman S. Borschel made changes -
        Fix Version/s 2.0-BETA1 [ 10030 ]
        Roman S. Borschel made changes -
        Status In Progress [ 3 ] Closed [ 6 ]
        Resolution Fixed [ 1 ]
        Benjamin Eberlei made changes -
        Workflow jira [ 11052 ] jira-feedback [ 15582 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback [ 15582 ] jira-feedback2 [ 17446 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback2 [ 17446 ] jira-feedback3 [ 19703 ]

          People

          • Assignee:
            Roman S. Borschel
            Reporter:
            Ondrej Sibrina
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: