We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42577
    • 5 Posts
    Below code of schema. I've added extended table, table users and table with attrubutes.

    Also wrote a component that shows data from extended table, it works fine.
    But when I remove one item from datagrid (in a backend) it removes item from users and extended users table and not from attributes table. What can I do or how to change schema for it ?

    <?xml version="1.0" encoding="UTF-8"?>
     
    
    <model package="extendeduinfo" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM">
         
         
        <object class="ExtendedUser" table="users" extends="xPDOSimpleObject">
            <field key="id" dbtype="int" precision="11" phptype="integer" null="false" index="pk"  generated="native" />
            <field key="username" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
            <index alias="PRIMARY" name="PRIMARY" primary="true" unique="true">
                <column key="id" collation="A" null="false" />
            </index>
            <composite alias="ExtendedOneUser" class="ExtendedOneUser" local="id" foreign="user" cardinality="many" owner="local" />
             
             
        </object>
          
        <object class="ExtendedUserAttribute" table="user_attrubutes" extends="xPDOSimpleObject">
            <field key="id" dbtype="int" precision="11" phptype="integer" null="false" index="pk"  generated="native" />
            <field key="internalKey" dbtype="int" precision="11" phptype="integer" null="true" />
     
            <index alias="PRIMARY" name="PRIMARY" primary="true" unique="true">
                <column key="id" collation="A" null="false" />
            </index>
            <composite alias="ExtendedOneUser" class="ExtendedOneUser" local="internalKey" foreign="user" cardinality="many" owner="local" />
             
        </object> 
              
        <object class="ExtendedOneUser" table="userextendlist" extends="xPDOSimpleObject">
            <field key="id" dbtype="int" precision="11" phptype="integer" null="false" index="pk"  generated="native" />
            <field key="user" dbtype="int" precision="11" phptype="integer" null="true" />
            <field key="fb_id" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
            <field key="tw_id" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
            <field key="vk_id" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
            <field key="gp_id" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
            <field key="mobile" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
            <field key="avatar" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
            <index alias="PRIMARY" name="PRIMARY" primary="true" unique="true">
                <column key="id" collation="A" null="false" />
            </index>
            <composite alias="ExtendedUser" class="ExtendedUser" local="user" foreign="id" cardinality="one" owner="foreign" />
            <composite alias="ExtendedUserAttribute" class="ExtendedUserAttribute" local="internalKey" foreign="id" cardinality="one" owner="foreign" />
         
             
        </object> 
     
     
     
     
    </model>
      • 42602
      • 81 Posts
      The ExtendedUserAttribute object is the issue, or not issue but needs bit of refining.

      First the :
      <field key="id" dbtype="int" precision="11" phptype="integer" null="false" index="pk"  generated="native" />

      is not necessary. xPDOSimpleObject has native id field with auto_increment. That is actually the only difference with xPDOObject and it. So you can remove it and rebuild the map. Check that the field still exists in the database. There should not be problems with the transition. Or just simply change the object type to xPDOObject.

      Second :

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

      should look like
      <composite alias="ExtendedUserAttribute" class="ExtendedUserAttribute" local="id" foreign="id" cardinality="one" owner="local" />

      There is no internalKey field in your table so it cannot do the removal nor joins to ExtendedUserAttribute "magically". Also with composites the owner should be local as it is the "parent" of the attributes. By reading the schema, the foreign="id" could might be foreign="internalKey" actually.
        • 42577
        • 5 Posts
        Thanks for your help! I didn't know about difference of xPDOSimpleObject and xPDOObject (that id is auto_increment automatically with Simple)

        About second part, internalKey is a field of default table modx_user_attributes. So I changed the schema to the follow

        <?xml version="1.0" encoding="UTF-8"?>
        <model package="extendeduinfo" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM">
            
        	
        	<object class="ExtendedUser" table="users" extends="xPDOSimpleObject">
        
        		<field key="username" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
        		<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true">
        			<column key="id" collation="A" null="false" />
        		</index>
        		<composite alias="ExtendedOneUser" class="ExtendedOneUser" local="id" foreign="user" cardinality="many" owner="local" />
        		
        		
        	</object>
        	 
        	<object class="ExtendedUserAttribute" table="user_attrubutes" extends="xPDOSimpleObject">
        		<field key="internalKey" dbtype="int" precision="11" phptype="integer" null="true" />
        
        		<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true">
        			<column key="id" collation="A" null="false" />
        		</index>
        		<composite alias="ExtendedOneUser" class="ExtendedOneUser" local="internalKey" foreign="user" cardinality="many" owner="local" />
        		
        	</object>	
        		 
        	<object class="ExtendedOneUser" table="userextendlist" extends="xPDOSimpleObject">
        		<field key="user" dbtype="int" precision="11" phptype="integer" null="true" />
        		<field key="fb_id" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
        		<field key="tw_id" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
        		<field key="vk_id" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
        		<field key="gp_id" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
        		<field key="mobile" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
        		<field key="avatar" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
        		<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true">
        			<column key="id" collation="A" null="false" />
        		</index>
        		<composite alias="ExtendedUser" class="ExtendedUser" local="user" foreign="id" cardinality="one" owner="foreign" />
        		<composite alias="ExtendedUserAttribute" class="ExtendedUserAttribute" local="id" foreign="internalKey" cardinality="one" owner="local" />
        
        	
        		
        	</object>	


        I think it removes items from ExtendedUser table (it is a default users table) by local field "user", so thought it should remove item like this from ExtendedUserAttribute.

        With changed schema it also won't remove item from ExtendedUserAttribute