my question is how to delete entity on the inverse side without going through every association and delete it manually.
<?php
/** @Entity */
class User
{
// ...
/**
* @OneToMany(targetEntity="Address", mappedBy="user")
*/
private $addresses;
// ...
public function __construct() {
$this->addresses = new ArrayCollection();
}
}
/** @Entity */
class Address
{
// ...
/**
* @ManyToOne(targetEntity="User", inversedBy="features")
* @JoinColumn(name="user_id", referencedColumnName="id")
*/
private $user;
// ...
}
In this example, Address
is the owning side, so I can't delete User
because foreign key validation will fail. I have to delete Address
and then delete User
. If I have 10 relationships like these the delete process is painful.
I can create ManyToMany
relationship, but this way the Address
entity will have users
not user
and I want addresses to have only one user.
What is the best way to do this?