Details
Description
Test.php
/*
* @Entity
* @Table(indexes={@Index(name="name", columns={"name"})})
*/
class ProductAttribute
{
/**
* ID
*
* @Id @Column(type="integer") @GeneratedValue
*
* @var integer
*/
protected $id;
/**
* Name
*
* @Column
*
* @var string
*/
protected $name;
/**
* Values
*
* @OneToMany(targetEntity="ProductAttributeValue", mappedBy="attribute")
*
* @var array
*/
protected $values;
/**
* Gets ID
*
* @return integer ID
*/
public function getId()
{
return $this->id;
}
/**
* Sets ID
*
* @param integer $id ID
*
* @return void
*/
public function setId($id = null)
{
$this->id = $id;
}
/**
* Gets name
*
* @return string Name
*/
public function getName()
{
return $this->name;
}
/**
* Sets name
*
* @param string $name Name
*
* @return void
*/
public function setName($name = null)
{
$this->name = $name;
}
/**
* Gets product attribute values
*
* @return array Product attribute values
*/
public function getValues()
{
return $this->values;
}
/**
* Adds product attribute value
*
* @param ProductAttributeValue $value Product attribute value
*
* @return void
*/
public function addValue(ProductAttributeValue $value)
{
$value->setAttribute($this);
$this->values[] = $value;
}
}
$attribute = $em->find('ProductAttribute', 1);
$em->remove($attribute);
$em->flush();
The upper code won't remove the entity from the database.... Corresponding DQL (DELETE ProductAttribute a WHERE a.id = 1) will remove it from the database...
I just found out, that when I have an entity containing a *ToMany column with cascade=
{"remove"}set, all the entities are removed, except for the one...