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.]