We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14883 ☆ A M B ☆
    • 450 Posts
    I was writing a plugin last week that created users & profiles, and in the process I was creating & deleting some user & profile records manually in the db tables. Now it seems that my auto-increment ID for modx_users is out of sync with the one in modx_user_attributes. If a new user ID is 16, the ID of the profile will be 18.

    It doesn’t look like this should be a problem, because the profiles correctly link to the right user ID on the "internalKey" field: in the modx_user_attributes table, the record for profile with id=18 has internalKey=16. And from inside of Manager I can see the right profile info when I edit the user. But standard API calls are not working right:

    $user = $modx->getObject('modUser', $id);
    $prof = $user->getOne('modUserProfile'); // this fails


    Or,
    $user = $modx->getObjectGraph('modUser', '{"Profile":{}}', $id );
    return $user->profile->get('fullname'); // this fails
    


    I know I could hack my way through this by doing something like:
    $prof = $modx->getObject('modUserProfile', array('internalKey'=>$id));


    But that doesn’t seem like a long-term solution.

    Is this a bug in how $user->getOne(’modUserProfile’) works? Keying on id instead of ’internalKey’? Or what might be going on here?


      • 22303 MODX Staff
      • 10,725 Posts
      It’s getOne(’Profile’) not modUserProfile. You have to refer by the alias of the relationship.
        • 3749
        • 24,544 Posts
        Also, with getObjectGraph(), it should be (capital P in "Profile"):

        return $user->Profile->get('fullname');
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 14883 ☆ A M B ☆
          • 450 Posts
          Cause-jumping and bad syntax. Not a good combination.

          Thanks guys.