I’m working on a snippet, but I cant get the addOne function to work.
Here is my schema:
<object class="Companies" table="supdesk_companies" extends="xPDOSimpleObject">
<field key="name" dbtype="varchar" phptype="string" precision="100" null="false" default="" />
<composite alias="Locations" class="Locations" local="id" foreign="company_id" cardinality="many" owner="local" />
</object>
<object class="Locations" table="supdesk_locations" extends="xPDOSimpleObject">
<field key="company_id" dbtype="int" precision="10" phptype="integer" null="false" default="" />
<field key="city" dbtype="varchar" phptype="string" precision="100" null="false" default="" />
<aggregate alias="Company" class="Companies" local="company_id" foreign="id" cardinality="one" owner="foreign" />
</object>
getOne works like a charm, but addOne doesn’t.
If a use:
$newcompany = $modx->newObject('Companies', array(
'name' => 'My Company Name'
));
$newlocation = $modx->newObject('Locations', array(
'city' => 'Amsterdam'
));
$newcompany->addOne($newlocation);
$newcompany->save();
- The Companytable is added in phpmyadmin and the company is added with the name ’My Company Name’.
- The new locationtable is added in phpmyadmin, but the location is not added.
Does anyone knows how this is possible?
----
By the way: I can use $newlocation->save(); and the location gets saved, but I need to link the two.
----
I’m working with MAMP, and I’m using modx revolutino 2.08
Regards,
Rogier