Jira issue originally created by user legolas:
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();
$purc->addProduct($prod); //Added a new product to the collection
$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(); //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.