Reputation: 1956
I'm working on a project where I never actually delete any records. I am trying to get Doctrine to set an entity to "deleted" (flag) on cascade. Here are two entities to illustrate the associations I have currently;
Model_Account
/**
* @OneToMany(targetEntity="Model_Profile",mappedBy="Account")
*/
protected $Profiles;
Model_Profile
/**
* @ManyToOne(targetEntity="Model_Account",inversedBy="Profiles")
* @JoinColumn(name="AccountId",referencedColumnName="Id",onDelete="CASCADE")
*/
protected $Account;
When I delete an account, I wish all profiles associated with said account to be removed also, but only by having their "Deleted" flag set to true. I have no idea where to go from here. Do I need to tap into an event to override the default delete and just set my flag?
Thank you.
Upvotes: 2
Views: 1293
Reputation: 11122
Set up Doctrine2 soft delete (there's an extension for it) and then use Doctrine's cascade operations instead of those at the RDBMS level by setting cascade={"remove"}
on the entity.
Upvotes: 1