How are your two tables related to one another? I don't think you want to use aggregate relationships in both objects. There should be a composite relationship somewhere.
Let's make some assumptions:
1. First assumption:
A fund request can only be submitted by one entity a time. An entity can submit more than one fund request. We're here in the presence of a
One-to-Many relationship with entities being the primary table.
In this case, your schema could look like this:
<object class="Entities" table="entities" extends="xPDOSimpleObject">
<field key="token" dbtype="varchar" precision="50" phptype="string" null="true" />
<field key="unixtime" dbtype="varchar" precision="50" phptype="string" null="true" />
<composite alias="Request" class="FundRequests" foreign="payee_uid" local="id" cardinality="many" owner="local" />
</object>
<object class="FundRequests" table="fund_request" extends="xPDOSimpleObject">
<field key="token" dbtype="varchar" precision="50" phptype="string" null="true" />
<field key="unixtime" dbtype="varchar" precision="50" phptype="string" null="true" />
<field key="payee_uid" dbtype="int" precision="8" phptype="integer" null="true" />
<field key="client_uid" dbtype="int" precision="8" phptype="integer" null="false" />
<aggregate alias="Payee" class="Entities" local="payee_uid" foreign="id" cardinality="one" owner="foreign" />
</object>
I went with your logic, but I'm not sure why you're using two similar fields (client_uid, payee_uid) to define your relationship. Based on your schema, I have a feeling that a client can be a payee. I've therefore omitted
client_uid from the relationship.
2. Second assumption
A fund request can be linked to many entities and an entity can submit many fund requests. This is a
Many-to-Many relationship. Both tables are primary. In this case we need a join table to bridge them. Let's call it
request_entities.
Our schema could look like this:
<object class="Entities" table="entities" extends="xPDOSimpleObject">
<field key="token" dbtype="varchar" precision="50" phptype="string" null="true" />
<field key="unixtime" dbtype="varchar" precision="50" phptype="string" null="true" />
<composite alias="requestEntity" class="RequestEntities" foreign="payee_uid" local="id" cardinality="many" owner="local" />
</object>
<object class="FundRequests" table="fund_request" extends="xPDOSimpleObject">
<field key="token" dbtype="varchar" precision="50" phptype="string" null="true" />
<field key="unixtime" dbtype="varchar" precision="50" phptype="string" null="true" />
<field key="payee_uid" dbtype="int" precision="8" phptype="integer" null="true" />
<field key="client_uid" dbtype="int" precision="8" phptype="integer" null="false" />
<composite alias="requestEntity" class="RequestEntities" foreign="request" local="id" cardinality="many" owner="local" />
</object>
<object class="RequestEntities" table="request_entities" extends="xPDOSimpleObject">
<field key="request" dbtype="int" precision="8" phptype="integer" null="true" />
<field key="payee_uid" dbtype="int" precision="8" phptype="integer" null="true" />
<aggregate alias="Payee" class="Entities" local="payee_uid" foreign="id" cardinality="one" owner="foreign" />
<aggregate alias="Request" class="FundRequests" local="request" foreign="id" cardinality="one" owner="foreign" />
</object>
As noted earlier, I've omitted the
client_uid field in the relationship definitions because I have a feeling it doesn't belong there. I may be wrong. It would be helpful if you could describe how a payee is different from a client and why it should be defined in the relationship.
I hope I didn't misunderstand you.
[ed. note: treigh last edited this post 11 years, 9 months ago.]