We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26503
    • 620 Posts
    argh - everything looks right ~ no errors thrown anywhere. ere is what I have:

    schema:

    <?xml version="1.0" encoding="UTF-8"?>
    
    <model package="extuser" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1" >
    
        <object class="extUser" extends="modUser">
            <composite alias="UserData" local="id" class="Userdata" foreign="internalKey" cardinality="one" owner="local" />
            <composite alias="UserQueries" local="id" class="UserQueries" foreign="internalKey" cardinality="many" owner="local" />
        </object>
    
        <object class="UserData" table="user_ext_data" extends="xPDOSimpleObject">
            <field key="internalKey" dbtype="int" precision="10" phptype="integer" null="true" />
            <field key="location" dbtype="varchar" precision="50" phptype="string" null="true" />
            <aggregate alias="extUser" local="internalKey" foreign="id" cardinality="one" owner="foreign" />
        </object>
    
        <object class="UserQueries" table="user_queries" extends="xPDOSimpleObject">
            <field key="internalKey" dbtype="int" precision="10" phptype="integer" null="false" />
            <field key="date" dbtype="time" phptype="string" null="false" />
            <field key="query" dbtype="longtext" phptype="string" null="false" />
            <aggregate alias="extUser" local="internalKey" foreign="id" cardinality="one" owner="foreign" />
        </object>
    
    </model>



    Just trying a little test snippet which fails when I try to output the UserData object:


    $modx->addPackage('extuser', MODX_CORE_PATH . 'components/extuser/model/');
    
    $user = $modx->getObject('extUser', 2); // where 123 is the id of a user
    
    echo $user->get('username');
    
    $data = $user->getOne('UserData'); // use the alias from the schema
    
    if($data){echo 'got data<br>';}else{echo 'nodata<br>';}
    
    //toArray will print all the extra data, e.g. facebook_url
    
    //return print_r($data->toArray(), true);



    and looking at the class map, everything looks good there:

    <?php
    $xpdo_meta_map['UserData']= array (
      'package' => 'extuser',
      'version' => '1.1',
      'table' => 'user_ext_data',
      'extends' => 'xPDOSimpleObject',
      'fields' => 
      array (
        'internalKey' => NULL,
        'location' => NULL,
      ),
      'fieldMeta' => 
      array (
        'internalKey' => 
        array (
          'dbtype' => 'int',
          'precision' => '10',
          'phptype' => 'integer',
          'null' => true,
        ),
        'location' => 
        array (
          'dbtype' => 'varchar',
          'precision' => '50',
          'phptype' => 'string',
          'null' => true,
        ),
      ),
      'aggregates' => 
      array (
        'extUser' => 
        array (
          'local' => 'internalKey',
          'foreign' => 'id',
          'cardinality' => 'one',
          'owner' => 'foreign',
        ),
      ),
    );




    - yes there is data in the new database tables
    - the class key was changed for all users
    - no errors in modx or apache logs


    Help! sad
      *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

      Sean Kimball CLP, CLS.
      Technical Director / Sr. Developer | BigBlock Studios
      ._______________________________________________.
      Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
      27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
      phone/fax: 905-426-5525
      • 3749
      • 24,544 Posts
      Are you using ClassExtender? http://bobsguides.com/classextender-class.html That will do most of the work for you and there are some utility snippets to help retrieve the data. It will also (optionally) register the class in the extension_packages System Setting so it will be loaded on every request and you don't have to call addPackage().

      I think your problem may be that the primary key for the data would be 'id' (based on the class you're extending), so you're trying to retrieve the object with an ID of 2 rather than:

      $user = $modx->getObject('extUser', array('internal_key' => 2));


      (Unless you're manually setting 'internal_key' to equal 'id' somewhere.)

      You might also want to test the return value of addPackage(). It will be empty on failure.

        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
        • 26503
        • 620 Posts
        I tinkered with classExtender, but I have 2 [and more to come] tables to work with, it does not handle more than the one default...

        It is registered as an extension package [there was an error in the logs on every request when it wasn't]

        Where is 'internal_key' coming from? [is that a typo, you mean internalKey?]

        When I run this: $user = $modx->getObject('extUser', 2); ~ I get the correct user, but I thought that the alias in the schema [ <composite alias="UserData" local="id" class="Userdata" foreign="internalKey" cardinality="one" owner="local" /> ] took care of relating that user to the user data... ? so I shouldn't have to pass the internalKey as part of the getObject [I should be able to use getOne for the UserData & getMany for the UserQueries]



        Quote from: BobRay at Jul 18, 2014, 05:48 AM
        Are you using ClassExtender? http://bobsguides.com/classextender-class.html That will do most of the work for you and there are some utility snippets to help retrieve the data. It will also (optionally) register the class in the extension_packages System Setting so it will be loaded on every request and you don't have to call addPackage().

        I think your problem may be that the primary key for the data would be 'id' (based on the class you're extending), so you're trying to retrieve the object with an ID of 2 rather than:

        $user = $modx->getObject('extUser', array('internal_key' => 2));


        (Unless you're manually setting 'internal_key' to equal 'id' somewhere.)

        You might also want to test the return value of addPackage(). It will be empty on failure.

          *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

          Sean Kimball CLP, CLS.
          Technical Director / Sr. Developer | BigBlock Studios
          ._______________________________________________.
          Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
          27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
          phone/fax: 905-426-5525
          • 26503
          • 620 Posts
          So now, while existing users can log in, administrators cannot unless I change their class key back to modUser
          Also, looking around to see how I can set the class_key for new user registration .... huh does this need to be done in a post hook?

          :(
            *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

            Sean Kimball CLP, CLS.
            Technical Director / Sr. Developer | BigBlock Studios
            ._______________________________________________.
            Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
            27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
            phone/fax: 905-426-5525
            • 3749
            • 24,544 Posts
            Yes, I did mean internalKey. wink

            I think the problem with admin logins may go away if you flush both permissions and sessions and delete all files in the core/cache directory.

            The trick is not to reset all the existing class_keys too soon. If you do it right after you create the class files, MODX doesn't know about the class yet because of the cache.

            To set the class key for new users, do something like this in the extended class:

            class extUser extends modUser {
                function __construct(xPDO & $xpdo) {
                    parent::__construct($xpdo);
                    $this->set('class_key', 'extUser');
                }
            }
            


              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
              • 26503
              • 620 Posts
              Yes all the login problems went away after clearing caches & sessions... though I am still setting new users to extUser with a posthook on the register snippet.

              $hook->setValue('class_key', 'extUser');


              Still no luck getting/setting the extuser data though!


              Quote from: BobRay at Jul 19, 2014, 04:27 AM
              Yes, I did mean internalKey. wink

              I think the problem with admin logins may go away if you flush both permissions and sessions and delete all files in the core/cache directory.

              The trick is not to reset all the existing class_keys too soon. If you do it right after you create the class files, MODX doesn't know about the class yet because of the cache.

              To set the class key for new users, do something like this in the extended class:

              class extUser extends modUser {
                  function __construct(xPDO & $xpdo) {
                      parent::__construct($xpdo);
                      $this->set('class_key', 'extUser');
                  }
              }
              


                *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

                Sean Kimball CLP, CLS.
                Technical Director / Sr. Developer | BigBlock Studios
                ._______________________________________________.
                Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
                27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
                phone/fax: 905-426-5525
                • 26503
                • 620 Posts
                I got it working.... classic case of case & syntax: I was using:

                <composite alias="UserData" local="id" class="Userdata" foreign="internalKey" cardinality="one" owner="local" />
                


                but calling:

                $data = $user->getOne('UserData'); // use the alias from the schema
                


                the alias was correct, but the class was called Userdata instead of UserData ... grr
                  *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

                  Sean Kimball CLP, CLS.
                  Technical Director / Sr. Developer | BigBlock Studios
                  ._______________________________________________.
                  Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
                  27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
                  phone/fax: 905-426-5525
                  • 3749
                  • 24,544 Posts
                  I'm glad you got it sorted. We've all been there. wink
                    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