In typical user management CRUD apps, it's a common case to have to remove users from a group or add them to them - it would be easier if we could do this like so:
$user->changeGroups($_POST['groups']);
Right now, we have to:
Get group IDs from a form
Compare with current group IDs on a user
Revoke any that no longer appear in data from form
Add any new ones that appear in data from form
This is, for obvious reasons, incredibly impractical.
I suggest implementing a new changeGroups method which would remove ALL groups from a user, and at the same time add those we're feeding it. The method should be wrapped in a transaction in order to be safe against failures and leaving a user without groups should something break mid-way.
In typical user management CRUD apps, it's a common case to have to remove users from a group or add them to them - it would be easier if we could do this like so:
Right now, we have to:
This is, for obvious reasons, incredibly impractical.
I suggest implementing a new
changeGroups
method which would remove ALL groups from a user, and at the same time add those we're feeding it. The method should be wrapped in a transaction in order to be safe against failures and leaving a user without groups should something break mid-way.