We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9207 ☆ A M B ☆
    • 2,475 Posts
    I’m trying to create hierarchical user groups via xPDO, but when I set the "parent" attribute, it doesn’t seem to stick... when I view the user groups via "Security --> Access Controls", the user group is never created as a child of the user group I’m trying to make it a child of.

    Here’s the code snippet:

    			$UG = $modx->newObject('modUserGroup');
    			$datestamp = date("Y-m-d H:i:s");
    			$UG->set('name', $new_name );
    			$UG->set('description', 'Automatically created '.$datestamp);
    			$UG->set('parent', 8 ); // hard-coded: all new user groups are children of the "Clients (8)"
    			$UG->save();
    


    Curiously, I’ve noticed that some of the user groups I’ve deleted via the MODx manager are still present in the database:
    select * from modx_membergroup_names;


    What gives? Can I not hard-code the parent like that?
      • 9207 ☆ A M B ☆
      • 2,475 Posts
      Ack, I’m a moron: I was editing the wrong controller.

      However, the issue with some residual User Groups persisting in the database is still there -- why don’t those get deleted correctly?