- Create a model listener for the user model
public class BugDemoModelListener extends BaseModelListener<User>
- Override onBeforeAddAssociation method
- Access the old user roles (before the new one is added)
- You can access the old user roles and perform some custom logic without any effects
- As soon as you call user.getRoles() from the onBeforeAddAssociation method the gui of the control panel -> edit user -> roles doesn't show the newly added role. You have to restart the server because the cache was cleared at the wrong time.
- If you want to access the user roles (even if it's just for System.outs) in the onBeforeAddAssociation method you have to manually clear the cache so that the control panel gui is showing the newly added role as expected:
This could also effect the caching of all other associations (not just for user roles)!