I have got problem with unidirectional ManyToMany relationship in Doctrine. The case is very easy: Product has many Tags. Tag can be attached to Product but also to any \"taggab
Ok, I managed myself by digging in Doctrine2 docs ;) Solution is to add onDelete="cascade" to @JoinColumn.
/**
* @Entity
* @Table(name="products")
**/
class Product {
/** some other fileds here */
/**
* @ManyToMany(targetEntity="Tag")
* @JoinTable(name="products_tags",
* joinColumns={@JoinColumn(name="product_id", referencedColumnName="id", onDelete="cascade")},
* inverseJoinColumns={@JoinColumn(name="tag_id", referencedColumnName="id", onDelete="cascade")}
* )
*/
protected $tags;
}
Note that, cascade={"all"} is managed on object level (in your app), while onDelete="cascade" is on database level.