[FLOW3-general] Doctrine's removeElement() deletes objects without repository update

Martin Lipp martin.lipp at gmail.com
Mon Feb 13 22:04:28 CET 2012


Is it intended that the Doctrine ArrayCollection removeElement($object) 
function forces the deletion of $object out of the database? I always 
was of the opinion that only repository functions like update() or 
delete() are able to do persistence stuff.
After testing a little bit it seems not to happen with every of my 
models, but I'm not able to see any difference between the models.


Models:

/**
  * A Album
  *
  * @FLOW3\Scope("prototype")
  * @FLOW3\Entity
  */
class Album {

	/**
	 * The images
	 * @var \Doctrine\Common\Collections\Collection<...\Domain\Model\Image>
	 * @ORM\OneToMany(mappedBy="album")
	 * @ORM\OrderBy({"fileName" = "ASC"})
	 */
	protected $images;
...
	/**
	 * Removes an image from this album
	 *
	 * @param ...\Domain\Model\Image $image
	 * @return void
	 */
	public function removeImage(...\Domain\Model\Image $image) {
		$this->images->removeElement($image);
	}

...

/**
  * A Image
  *
  * @FLOW3\Scope("prototype")
  * @FLOW3\Entity
  */
class Image {
	/**
	 * The album
	 * @var ...\Domain\Model\Album
	 * @ORM\ManyToOne(inversedBy="images")
	 */
	protected $album;

	/**
	 * The persons
	 * @var \Doctrine\Common\Collections\Collection<...\Domain\Model\Person>
	 * @ORM\ManyToMany(inversedBy="images")
	 */
	protected $persons;

...

/**
  * A Person
  *
  * @FLOW3\Scope("prototype")
  * @FLOW3\Entity
  */
class Person {
	
	/**
	 * The images tagged with this person
	 *
	 * @var 
\Doctrine\Common\Collections\Collection<\LA\SCGussendorf\Domain\Model\Image>
	 * @ORM\ManyToMany(mappedBy="persons")
	 */
	protected $images;

...


Only the AlbumRepository exists. A simple $album->removeImage($image) 
(without $this->albumRepository->update($album) ) deletes the image, the 
ManyToMany relation and even the connected Persons from the database. 
$image->removePerson($person) for instance only deletes the ManyToMany 
entry in the join table (and only after the update() command).

Martin


More information about the FLOW3-general mailing list