Reputation: 1751
According to the documentation and this post I just need to specify onDelete="CASCADE" in the @ORM\JoinColumn and it should make a foreign key that cascades on delete. I did that..
/**
* @ORM\OneToMany(targetEntity="OrderDates", mappedBy="order", cascade={"persist", "remove"}, orphanRemoval=TRUE)
* @ORM\JoinColumn(name="order_id", referencedColumnName="id", onDelete="CASCADE")
*/
private $dates;
however when I make the migration, the FK it generates doesn't cascade on delete.
ALTER TABLE order_dates ADD CONSTRAINT FK_28EABDE38D9F6D38 FOREIGN KEY (order_id) REFERENCES orders (id)
I tried removing the , cascade={"persist", "remove"}, orphanRemoval=TRUE
part too but to no avail.
Edit: I've also tried setting it on the inverse side but it doesn't work either (in fact NO foreign key is made at all when I do this):
/**
* @ORM\ManyToOne(targetEntity="Orders", inversedBy="dates", cascade={"persist"})
* @ORM\JoinColumn(name="order_id", referencedColumnName="id", onDelete="CASCADE")
*/
private $order;
Upvotes: 1
Views: 1869
Reputation: 2827
onDelete="CASCADE"
works on the owning side (inversedBy), not the inverse side (mappedBy).
Upvotes: 2