We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38970
    • 59 Posts
    Hey Guys,

    I am trying to extend mod user to have a relationship with another table so I can store "goals" that have been completed by each user. Here is my Schema:

    <?xml version="1.0" encoding="UTF-8"?>
    <model package="Offer_Status" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
            <object class="extUser" table="modx_users" extends="modUser">
                <composite alias="OfferSummary" local="id" foreign="UserId" cardinality="many" owner="local" />
            </object>
    	<object class="OfferSummary" table="modx_offer_summary" extends="xPDOSimpleObject">
    		<field key="UserId" dbtype="int" precision="11" phptype="integer" null="false" index="index" />
    		<field key="OfferId" dbtype="int" precision="11" phptype="integer" null="false" />
    		<field key="CompleteDate" dbtype="timestamp" phptype="timestamp" null="false" default="CURRENT_TIMESTAMP" />
    		<field key="OfferStatus" dbtype="tinyint" precision="1" phptype="integer" null="false" />
    
    		<index alias="UserId" name="UserId" primary="false" unique="false" type="BTREE" >
    			<column key="UserId" length="" collation="A" null="false" />
    			<column key="CompleteDate" length="" collation="A" null="false" />
    		</index>
                    <aggregate alias="extUser" local="UserId" foreign="id" cardinality="one" owner="foreign" />
    	</object>
    </model>


    I have followed the tutorial in rtfm and I think I set it up properly. I also edited the class file extuser.class.php
    <?php
    /**
     * @package extendeduser
     * @subpackage user.mysql
     */
    class extUser extends modUser {
        function __construct(xPDO & $xpdo) {
            parent :: __construct($xpdo);
            $this->set('class_key','extUser');
        }
    }
    ?>


    Now my question is all the users in the table modx_users have the class key of modUser, do i have to create new users (via the api) to be able to use the extended fields, I would like all users to be able to have access to extended fields.

    If I change my user manually in the database to extUser it automatically logs me out and cant log back in until i change it back to modUser.

    Also I havnt found any documentation on how to add data to my table so it creates the relationship with the current user.

    Any help is appreciated, kind of fumbling through all this as it is my first time with xpdo. [ed. note: datarecall last edited this post 14 years, 7 months ago.]
      • 3749
      • 24,544 Posts
      That's a great question. I can only answer part of it.

      You definitely don't want to change the class key of the existing users, because their fields will have to match those in the schema for that table.

      Someone who knows more than I do will have to chime in no whether you need to migrate the existing users to the new table. I'd first look at the new table and see if it has the user fields you didn't specify in your extendeduser class.


      ---------------------------------------------------------------------------------------------------------------
      PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
      MODX info for everyone: http://bobsguides.com/modx.html

        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
        • 38970
        • 59 Posts
        Thanks for the information.. So I added a user via the manager console and it automatically put the key in as mod user. How do I set the fault class key to use my extended class. Or do inhave to add all users in the API method?
          • 3749
          • 24,544 Posts
          Another good question. I don't know the answer to that. You might have to either create a snippet and form to make new users or a CMP.


          ---------------------------------------------------------------------------------------------------------------
          PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
          MODX info for everyone: http://bobsguides.com/modx.html
            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
            • 37975
            • 12 Posts
            Quote from: datarecall at Mar 10, 2012, 09:48 AM
            Thanks for the information.. So I added a user via the manager console and it automatically put the key in as mod user. How do I set the fault class key to use my extended class. Or do inhave to add all users in the API method?

            Look at the http://rtfm.modx.com/display/revolution20/OnBeforeUserFormSave . Maybe this can help you.
              never give up!