OK. I think I understand you.
I’m going to guess that your real problem is that you need to create the usergroup and the user objects properly using xPDO so that they have the proper relations. And you need to add the members to the user groups properly too. Something like this:
/* create a user group */
$groupName = 'SomeName';
$alreadyExists = $modx->getObject('modUserGroup',array('name' => $groupName));
if ($alreadyExists) return $modx->error->failure($modx->lexicon('user_group_err_already_exists'));
/* create group */
$usergroup = $modx->newObject('modUserGroup');
$usergroup->set('name',$groupName);
$usergroup->save();
/* add current user as a member */
$member = $modx->newObject('modUserGroupMember');
$member->set('user_group',$usergroup->get('id'));
$member->set('member',$modx->user->get('id'));
$member->set('role','some_role');
$usergroup->addMany($member);
/* save usergroup */
if ($usergroup->save() == false) {
return $modx->error->failure($modx->lexicon('user_group_err_create'));
}
Writing to the DB directly without going through xPDO is always risky and you can end up with confused relationships. Note: The stuff you did earlier may have left the DB in an unreliable state. It would be best to start with a fresh install.