We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 44580
    • 189 Posts
    I have the following schema (partial):
    <?xml version="1.0" encoding="UTF-8"?>
    <model package="add" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
            <object class="extUser" extends="modUser">
                    <composite alias="ParentDetail" class="ParentDetails" local="id" foreign="parent_id" owner="local" cardinality="one" />
            </object>
    
    	<object class="ParentDetails" table="parent_details" extends="xPDOSimpleObject">
    		<field key="parent_id" dbtype="int" precision="11" attributes="unsigned" phptype="integer" null="false" />
    		<field key="coach_id" dbtype="int" precision="11" attributes="unsigned" phptype="integer" null="false" />
    		<field key="hourly_rate" dbtype="int" precision="11" attributes="unsigned" phptype="integer" null="false" />
                    <aggregate alias="extUser" class="extUser" local="parent_id" foreign="id" cardinality="one" owner="foreign" />
    	</object>
    
    </model>


    A "parent" is a standard Modx user. When I delete the Modx user, I want the appropriate (one / one) record deleted from the parent_details table. This is not happening.

    I think I know why after discovering this: http://rtfm.modx.com/revolution/2.x/developing-in-modx/advanced-development/extending-moduser. After following this I tried to create a new user with a class key of extUser and got the error message: Could not load class: extUser from mysql.extuser.

    This is the value from the system setting extension_packages :
    [{"add":{"path":"[[++core_path]]components/add/model/","tablePrefix":"add_"}}]


    This is the contents of core/components/add/model/add/extuser.class.php:
    <?php
    class extUser extends modUser {
        function __construct(xPDO & $xpdo) {
            parent::__construct($xpdo);
            $this->set('class_key','extUser');
    }


    I seem to be missing something. Anyone know what?
      • 3749
      • 24,544 Posts
      I could be wrong, but I think in the latest versions of MODX, the extension_packages System Setting may be ignored, since there is now a modx_extension_packages table in the DB. Even if it's not ignored, what's in the DB table may take precedence.

      As a last resort, you could override the remove() method in your class and remove the related object yourself before calling parent::remove();
        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
        • 44580
        • 189 Posts
        Thanks Bob. The extension_packages table is empty. Any idea how it gets populated?.

        As a last resort, you could override the remove() method in your class and remove the related object yourself before calling parent::remove();
        Yes, I could, but I'm using the standard User delete function and would strongly prefer for it to cascade to the children records as my composite/ aggregate relationships are supposed to. [ed. note: gissirob last edited this post 11 years, 9 months ago.]
          • 3749
          • 24,544 Posts
          I think the table is populated by the registerExtensionPackage() method.

          If the class_key is still modUser (as it would be for users created earlier), it would explain your problem. The modUser object doesn't know about your aliases.

            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
            • 44580
            • 189 Posts
            It's when I create a new user with the class_key 'extUser' that I get the error. So at the moment I can't even create users so I can delete them and their child records. In other words, I'm going backwards here smiley.
              • 3749
              • 24,544 Posts
              I would say you're going forward, since you now know what the problem is. wink

              You just need to figure out why you're getting that error. BTW, do things work in spite of the error?

              That error usually means that something is wrong with the extension_packages setting (or table), but you can also solve it by calling addPackage() ahead of the code that triggers the error.
                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
                • 44580
                • 189 Posts
                I would say you're going forward, since you now know what the problem is. wink
                Thanks for the pep-talk, I needed it smiley

                You just need to figure out why you're getting that error. BTW, do things work in spite of the error?
                No, they do not. I can create a user NP if I user class key: modUser, but it fails (with originally stated error) if I use extUser.

                That error usually means that something is wrong with the extension_packages setting (or table), but you can also solve it by calling addPackage() ahead of the code that triggers the error.
                Yes, but I'm not using any custom code at this point. I just want to create a user (cry).

                I'm currently trying different things with the extension_packages setting. Thanks for staying with me on this Bob.
                  • 3749
                  • 24,544 Posts
                  You did run a script to generate the class and map files from the schema, right? Also, if you change the schema, you need to run it again. The schema itself is ignored.

                    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
                    • 44580
                    • 189 Posts
                    Quote from: BobRay at Jan 16, 2015, 04:19 PM
                    You did run a script to generate the class and map files from the schema, right? Also, if you change the schema, you need to run it again. The schema itself is ignored.
                    Yeah I did all that good stuff, and even checked it at the filesystem. By way of further information, I have a quite complex system of additional tables, created using MIGdb and maintained using Migx CMPs (I removed all of this from the schema layout I posted at the beginning). This is all working fine. It is only when I try to add the final 'bit' (the relationships back to modUser), that problems began.

                    In fact, it is even more frustrating, because the only reason I need this relationship is when I delete users. All the rest of the workflow can happen without it.
                      • 3749
                      • 24,544 Posts
                      I think at this point, I'd just write a plugin attached to OnUserRemove and get on with life. 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