We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 2611
    • 394 Posts
    Hi there!

    xPDO has been very enjoyable so far...i’m from a world where MySQL query was totally cool...but xPDO
    beats the shit out of standard MySQL queries.

    One thing i like in perticulair is the relationships of the classes and objects. I’m trying to do
    something but i don’t know if it’s possible.

    What i’ve been able to do so far:
    Create a scheme that is linked to the modUser database and create a user based on it.

    What i’ve not been able to do:
    Create a relationship that defines that if the modUser is deleted (by modx) my agregate relationships
    will be gone as well.

    How can i create new composite relationships from modUser to my personal class? I can do this:

    <object class="rUser" extends="modUser">


    But this object will not be removed when i delete a modUser regardless of defined relationships.

    I hope i made myself clear,
    b03tz.
      Follow me on twitter: @b03tz
      Follow SCHERP Ontwikkeling on twitter: @scherpontwikkel
      CodeMaster
      • 22303 MODX Staff
      • 10,725 Posts
      Quote from: b03tz at Jun 24, 2010, 08:18 AM

      What i’ve been able to do so far:
      Create a scheme that is linked to the modUser database and create a user based on it.

      What i’ve not been able to do:
      Create a relationship that defines that if the modUser is deleted (by modx) my agregate relationships
      will be gone as well.

      How can i create new composite relationships from modUser to my personal class? I can do this:

      <object class="rUser" extends="modUser">


      But this object will not be removed when i delete a modUser regardless of defined relationships.
      You say you have extended the modUser object, but are you using the existing fields/table or trying to create your own modUser composite table object? Because extending modUser means you are going to use the existing table/fields. modUser employs single-table inheritance. Can you share your entire schema object?
        • 2611
        • 394 Posts
        Well, it’s nothing special...i’m just trying to link tables together so we’re facing something like this:

        <?xml version="1.0" encoding="UTF-8"?>
        <model package="testpackage" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM">
            
            <object class="rUser" extends="modUser">
            	<field key="internalKey" dbtype="int" precision="15" phptype="integer" null="false" default="" index="unique" />
            	
            	<composite alias="rProfile" class="rProfile" local="id" foreign="internalKey" cardinality="one" owner="local" />
            	
            	<aggregate alias="User" class="modUser" local="internalKey" foreign="id" cardinality="one" owner="foreign" />
            </object>
            
            <object class="rProfile" table="test_profiles" extends="xPDOSimpleObject">
            	<field key="internalKey" dbtype="int" precision="15" phptype="integer" null="false" default="" index="unique" />
            	<field key="name" dbtype="varchar" precision="100" phptype="string" null="false" default="" />
            	
            	<aggregate alias="rUser" class="rUser" local="internalKey" foreign="id" cardinality="one" owner="foreign" />
            </object>
            
        </model>


        I just want to define the relationship so that if i delete a modUser, his rProfile and rUser will be gone as well...
        Right now when i re-read this i’m doubting if i should use class="rUser" instead of class="modUser" in the aggregate
        relationship...gonna test this now ;-)

        Can you shed some light on this?
          Follow me on twitter: @b03tz
          Follow SCHERP Ontwikkeling on twitter: @scherpontwikkel
          CodeMaster
          • 22303 MODX Staff
          • 10,725 Posts
          First, don’t extend modUser by adding any columns; that is not supported here. You can add relationships, but you cannot change the modUser table structure. What you are trying to do is simply aggregate additional data from a custom table along with the modUser data. Extend modUser to add your custom rProfile class. Also, avoid mixed case column names like internalKey; that was maintained only for backwards compatibility with Evolution SQL queries and will change in future releases to reflect best practices.

          <?xml version="1.0" encoding="UTF-8"?>
          <model package="testpackage" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM">
              <object class="rUser" extends="modUser">    	
              	<composite alias="rProfile" class="rProfile" local="id" foreign="user" cardinality="one" owner="local" />
              </object>
              
              <object class="rProfile" table="test_profiles" extends="xPDOSimpleObject">
              	<field key="user" dbtype="int" precision="10" phptype="integer" attributes="unsigned" null="false" index="fk" />
              	<field key="name" dbtype="varchar" precision="100" phptype="string" null="false" default="" />
              	
              	<aggregate alias="rUser" class="modUser" local="user" foreign="id" cardinality="one" owner="foreign" />
              </object>
          </model>