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?