[英]Doctrine SoftDelete OneToOne Relationship
I have these entities on 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 it's a OneToOne relationship between Action and Review. 正如您所看到的,它是Action和Review之间的OneToOne关系。 My problem is I use soft-delete for my entities as well, so when I delete an entity is not actually removed only a deletion date is set.
我的问题是我也为我的实体使用软删除,所以当我删除一个实体实际上没有被删除时,只设置了一个删除日期。 Later in audit trail I need to show deleted reviews and I also need information from the parent action of course.
稍后在审计跟踪中,我需要显示已删除的评论,当然我还需要来自父操作的信息。 My question is, do I need to make this relationship OneToMany?
我的问题是,我是否需要与OneToMany建立这种关系? or is there a better approach?
还是有更好的方法?
To be honest i'm not very found of the soft-delete behaviour. 说实话,我不太了解软删除行为。 What you need to be aware is that soft-deleting an entity is a strong compromise in a relational database.
您需要注意的是,软删除实体是关系数据库中的一个强大妥协。
You may want to consider in this particular instance an event sourcing approach. 您可能希望在此特定实例中考虑事件采购方法。 I would recommend to store the information about the deletion and the (soft)deleted entity in a document based DB.
我建议在基于文档的数据库中存储有关删除和(软)删除实体的信息。
Any other approach (like OneToMany ) is still fine but keep in mind that the risk here is degrading your relation by introducing a incoherent relationship. 任何其他方法(如OneToMany )仍然可以,但请记住,这里的风险是通过引入不连贯的关系来降低您的关系。
That being said I'm fully aware that real life it's quite different than theory :) good luck. 话虽如此,我完全清楚现实生活与理论完全不同:)祝你好运。
Regards. 问候。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.