php - Symfony general entity relationship in Doctrine
I need to implement a PendingMessage class to store notifications for some of the entities of the Symfony2 app. Sometimes a notification will be created for one entity and sometimes for another one (there are many entities).
Is there any way to do an ORM relation in this PendingMessage class to store one entity but not an specific entity type, just a general entity (class), in order to have an attribute called '$destination' which should be an entity type.
Should I implement an interface? Any help is welcome!
You could add 2 parameters to your PendingMessage Entity, one
entityName, the other
With those parameters, you could access the repository in the controller like
If you want to do the same operation with this PendingMessage for every Entity possible, I'd write an Interface that will be used by every Repository you'll use, to that it's guaranteed that this function is given in every Repository that you'll receive dynamically.
If this isn't what your looking for, please clarify your question.
You can add field in PendingMessage entity in which You will store serialized entity for which this message was created.
Then if You would like to change this particular entity, You would do something like: