I'm new to Doctrine, mongo and the ODM setup and while playing with this setup in ZF1 I'm trying to replicate a simple one to many reference with a constraint. Here is the situation and would like some advise on how to achieve this.
This is a simple user->role mapping, so in a sql situation I would have tables as follows:
Users - id - name - role_id Roles - id - name
Then a foreign key constraint would be set on the users role_id to map to the role id. And upon deleting a role a foreign key constraint would be triggered stopping the operation.
How could I achieve the same goal in Doctrines MongoDB ODM?
So far I have played with different types of annotations on the User entity including @ReferenceOne @ReferenceMany with different cascade options...
The choice left to me now is to implement @PreUpdate, @PreRemove lifecycle events on the 'role' entity and then check that no users are using the role, if they are then on update change the reference to match or on remove throw an exception.
Am I right here or lost ?
Thank you,
Si