1

I have a Company entity with a one to many relationship with Location. (A Company can have multiple locations).

Location has a boolean "isPrimaryLocation".

Before saving (new/edit) a Location to the database I always want the following logic to be checked:

Enforce that IF there is a Location for a company, there has to be ONE isPrimaryLocation and maximum ONE location is isPrimaryLocation.

So my questions:

  • Is this something that can be enforced with Doctrine Annotations?
  • Is this something that I should to do with LifeCycleCallbacks and PrePersist?
  • Is this something that I should to with a Custom Event and a EventListener?
4

1 回答 1

1

我会在 prePersist 事件上添加一个自定义 EventListener。

于 2013-06-04T13:16:28.100 回答