Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2528

Extracting entities through DQL query resets the previous associations

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.0
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      Windows 8

      Description

      I have the entities Purchase(owning side) and Product(inverse side) sharing bidirectional many to many relation. Now whatever associations I build between product and purchase entity, those associations are erased if by mistake I happen to run a join query between the products and purchase table. For example look at this code.

      $purc = $em->find("\ZC\Entity\Purchase", 1); //Existing purchase entity
      //Now this purchase entity is linked to 2 products through the join table
      $prod = new \ZC\Entity\Product();
      $prod->name= "newly";
      $purc->addProduct($prod); //Added a new product to the collection
      // print(count($purc->products));
      $dql = "SELECT b,c FROM \ZC\Entity\Purchase b join b.products c where      b.id = 1";
      $query = $this->entityManager->createQuery($dql);
      $purc2 = $query->getResult()[0]; //Now this is same as $purc
      print(count($purc->products));   //again prints 2
      

      As you can see, when I have added a new entity $prod to the $purc, the number of products linked to $purc should have increased to 3. It seems the join overrides the previous associations formed. More strange is if I had fetched the products related to $purc from the tables before the join query(the commented code before dql), then the last print statement would have given 3.
      I am facing a lot of similar issues.

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Koustubh Sinhal
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: