We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34193
    • 330 Posts
    I am currently trying to get my head around having 2 groups of users in MODx who have a many to many relationship the basic idea is this

    Parents may have many Children
    Children may have many Parents

    Both Children and Parents are MODx users

    This is the schema I think will work but i’m not sure if this is even a valid idea in xPDO or not
    <?xml version="1.0" encoding="UTF-8"?>
    <model package="schoolmanagement" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" phpdoc-package="schoolmanagement" phpdoc-subpackage="model">
        <!-- inherit the modx user and extend it -->
        <object class="extUser" table="users" extends="modUser">
            <composite alias="Pupil_Details" class="pupil-details" local="id" foreign="User_ID_Child" cardinality="one" owner="local" />
            <composite alias="ParentOfChild" class="parent-child" local="id" foreign="User_ID_Child" cardinality="many" owner="local" />
            <composite alias="ChildOfParent" class="parent-child" local="id" foreign="User_ID_Parent" cardinality="many" owner="local" />
    
        </object>
    
        <!-- Parent - Children link table -->
        <object class="parent-child" table="parent-child" extends="xPDOSimpleObject">
            <field key="User_ID_Child" dbtype="int" phptype="integer" null="false" index="index" />
            <field key="User_ID_Parent" dbtype="int" phptype="integer" null="false" index="index"/>
            
            <aggregate alias="ChildOfParent" class="extUser" local="User_ID_Parent" foreign="id" cardinality="one" owner="foreign" />
            <aggregate alias="ParentOfChild" class="extUser" local="User_ID_Child" foreign="id" cardinality="one" owner="foreign" />
     
        </object>
    
        <!-- Children details -->
        <object class="pupil-details" table="pupil-details" extends="xPDOObject">
            <field key="User_ID_Child" dbtype="int" phptype="integer" null="false" index="pk" />
            <field key="RoleNum" dbtype="int" phptype="integer" null="false" index="index" />
    
            <field key="UPN" dbtype="varchar" precision="13" phptype="string" />
            <field key="Religion" dbtype="varchar" precision="30" phptype="string" />
            <field key="HomeLang" dbtype="varchar" precision="30" phptype="string" />
    
            <field key="Group" dbtype="varchar" precision="2" phptype="string" index="index" />
            <field key="YearGroup" dbtype="int" precision="2" phptype="integer" index="index"/>
            <field key="House" dbtype="varchar" precision="5" phptype="string" index="index"/>
            <field key="Status" dbtype="varchar" precision="10" phptype="string" />
    
            <aggregate alias="extUser" class="extUser" local="User_ID_Child" foreign="id" cardinality="one" owner="foreign" />
        
        </object>
    </model>
    


    I haven’t had time to try this yet since I am still writing the rest of the schema but wanted to check out if the idea would be workable before going too much further down this route.