Doctrine SoftDelete OneToOne Relationship
I have these entities in my code.
class Review extends BaseEntity {
/** @ORM\OneToOne(targetEntity="Action", mappedBy="review") */
protected $action;
}
class Action extends BaseEntity {
/** @ORM\OneToOne(targetEntity="Review", inversedBy="action") */
protected $review;
}
As you can see this is the OneToOne relationship between Action and Review. My problem is that I use soft-delete on my objects, so when I delete an entity, it doesn't actually delete, only the delete date is set. Later in the audit trail, I need to show the deleted reviews, and of course I need information from the parent activity. My question is, do I need to make this OneToMany relationship? or is there a better approach?
source to share
To be honest, I am not very well versed in soft-delete behavior. What you need to know is that soft object deletion is a strong tradeoff in a relational database.
You might want to consider the event source search approach in this particular case. I would recommend storing the delete and (soft) deleted object information in a document based database.
Any other approach (like OneToMany) is still fine, but keep in mind that the risk here worsens your attitude by introducing an incoherent relationship.
That being said, I am fully aware that in real life this is very different than theory :) Good luck.
Sincerely.
source to share