We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14911
    • 7 Posts
    I've been working on an add on for a client and could use some help troubleshooting the schema and subsequent relationships. See below for an excerpt from my schema file and the snippet I'm using to test.

    Snippet:
    $user = $modx->getUser();
    $link = $modx->newObject('LinksLink');
    $link->set('url','url_string_here');
    $link->set('anchortext','Test link');
    $added['link'] = $user->addMany($link);
    
    return var_export(array($added,$modx->errorInfo()),true);
    


    Schema excerpt:
        <object class="LinksLink" table="links_links" extends="xPDOSimpleObject">
    
            <field key="url" dbtype="text" phptype="string" null="false" default="" />
            <field key="anchortext" dbtype="varchar" precision="100" phptype="string" null="false" default="" />
            <field key="active" dbtype="tinyint" phptype="bool" null="false" default="0" />
            <field key="advertiser" dbtype="int" phptype="int" null="false" default="0" />
            <validation>
    	    <rule field="name"
    		  name="preventBlank"
    		  type="xPDOValidationRule"
    		  rule="xPDOForeignKeyConstraint"
    		  foreign="id"
    		  local="advertiser"
    		  alias="Advertiser"
    		  class="LinksUser"
    		  message="The category specified does not exist."
    	     />
    	</validation>
            <field key="category" dbtype="int" phptype="int" null="false" default="0" />
    	<validation>
    	    <rule field="name"
    		  name="preventBlank"
    		  type="xPDOValidationRule"
    		  rule="xPDOForeignKeyConstraint"
    		  foreign="id"
    		  local="category"
    		  alias="Category"
    		  class="LinksCategory"
    		  message="The category specified does not exist."
    	     />
    	</validation>
    
            <aggregate alias="Advertiser" class="LinksUser" local="advertiser" foreign="id" cardinality="one" owner="foreign" />
    	<composite alias="Publisher" class="LinksPublishers" local="id" foreign="link" cardinality="many" owner="local" />
    	<aggregate alias="Category" class="LinksCategory" local="category" foreign="id" cardinality="one" owner="foreign" />
    
        </object>
        <object class="LinksUser" extends="modUser">
    
            <composite alias="LinksSold" class="LinksPublishers" local="id" foreign="publisher" cardinality="many" owner="local" />
            <composite alias="Pages" class="LinksPublisherPages" local="id" foreign="publisher" cardinality="many" owner="local" />
            <composite alias="LinksCampaigns" class="LinksLink" local="id" foreign="advertiser" cardinality="many" owner="local" />
    	<composite alias="Opinions" class="LinksPublisherPageOpinion" local="id" foreign="Publisher" cardinality="many" owner="local" />
    	<composite alias="Key" class="LinksUserKey" local="id" foreign="user" cardinality="one" owner="local" />
    
        </object>
    


    I have a menial understanding of XPDO schemata, so if you see something obvious, don't hesitate to reply.

    EDIT:
    Sorry, I forgot to explain the problem I'm having. I can't seem to get addOne()/addMany to work on LinksUser/modUser Whether the object exists and I'm using getOne()/getMany(), or I'm creating a new object and using addOne()/addMany(), the relationships defined on LinksUser/modUser don't work in any direction. The addOne/addMany functions return false. Oddly enough, the relationships work between all the other objects I've defined.

    Also, I turned debugging on via $modx->setDebug(true);. This revealed an error message: "(ERROR @ /modx/index.php) No foreign key definition for parentClass: modUser using relation alias: LinksLink". What am I missing?

    Any advice or direction would be appreciated. [ed. note: jsewill last edited this post 14 years, 10 months ago.]
      • 14911
      • 7 Posts
      Well, I ended up figuring out what I needed to get this working. I figured I had missed something relatively simple. I had not understood that I needed to use the extension_packages system setting to include my package. That did it...that and changing the class_key field of the test user. My thanks to opengeek for putting up with my questions here and on the modx IRC channel.