correctly handle deleting and restoring unincluded memberships

make sure that if memberships are not included in a PUT we remove them
correctly and also, if there is an error saving the doc, we restore
them.