<object class="ContractBudgets" table="contract_budgets" extends="xPDOSimpleObject"> <field key="created" dbtype="timestamp" phptype="timestamp" null="true" default="CURRENT_TIMESTAMP" extra="on update current_timestamp" /> <field key="modified" dbtype="timestamp" phptype="timestamp" null="true" /> <field key="budget_type_id" dbtype="int" precision="8" phptype="integer" null="false" index="index" /> <field key="contract_id" dbtype="int" precision="8" phptype="integer" null="false" index="index" /> <field key="budget_f1" dbtype="decimal" precision="12,2" phptype="float" null="false" /> <field key="budget_f2" dbtype="decimal" precision="12,2" phptype="float" null="false" /> <field key="comment" dbtype="longtext" phptype="string" null="true" /> <aggregate alias="Contracts" class="Contracts" local="contract_id" foreign="id" cardinality="one" owner="foreign" /> </object> <object class="Contracts" table="contracts" extends="xPDOSimpleObject"> <field key="created" dbtype="timestamp" phptype="timestamp" null="false" default="CURRENT_TIMESTAMP" extra="on update current_timestamp" /> <field key="modified" dbtype="timestamp" phptype="timestamp" null="false" default="0000-00-00 00:00:00" /> <field key="status_id" dbtype="int" precision="8" phptype="integer" null="true" index="index" /> <field key="location_id" dbtype="int" precision="8" phptype="integer" null="false" /> <field key="client_id" dbtype="int" precision="8" phptype="integer" null="false" /> <field key="employer_id" dbtype="int" precision="8" phptype="integer" null="false" /> <field key="program_id" dbtype="int" precision="8" phptype="integer" null="false" /> <field key="requester_uid" dbtype="int" precision="8" phptype="integer" null="false" /> <field key="approver_uid" dbtype="int" precision="8" phptype="integer" null="false" /> <field key="start_date" dbtype="date" phptype="date" null="false" /> <field key="end_date" dbtype="date" phptype="date" null="false" /> <field key="start_balance" dbtype="decimal" precision="12,2" phptype="float" null="false" /> <field key="end_balance" dbtype="decimal" precision="12,2" phptype="float" null="true" /> <field key="comment" dbtype="longtext" phptype="string" null="true" /> <aggregate alias="StatusFlags" class="StatusFlags" local="status_id" foreign="id" cardinality="one" owner="foreign" /> <aggregate alias="Locations" class="Locations" local="location_id" foreign="id" cardinality="one" owner="foreign" /> <aggregate alias="Clients" class="Clients" local="client_id" foreign="id" cardinality="one" owner="foreign" /> <aggregate alias="Employers" class="Employers" local="employer_id" foreign="id" cardinality="one" owner="foreign" /> <aggregate alias="Programs" class="Programs" local="program_id" foreign="id" cardinality="one" owner="foreign" /> <composite alias="ContractBudgets" class="ContractBudgets" local="id" foreign="contract_id" cardinality="many" owner="local" /> </object>
/**
* Generic add data to database function
*
* @access public
* @param string $scriptProperties The properties for the snippet
* @param string $hook a reference to the formit hook data
* @return
*
*/
public function createDatabaseEntry($scriptProperties, & $hook){
//print_r($scriptProperties);exit();
$table = ucfirst($scriptProperties['table']);
$formfields = $hook->getValues();
///echo '<pre>';print_r($formfields);echo '</pre>';exit();
$newData = $this->modx->newObject($table);
foreach($formfields as $key => $value){
$newData->set($key,$value);
}
if(!$newData->save()){
$mess = $this->modx->lexicon('modflowthrough.add_'.$table.'_failed');
$this->modx->setPlaceholder('message_error',$mess);
return false;
}else{
$mess = $this->modx->lexicon('modflowthrough.add_'.$table.'_success');
$this->modx->setPlaceholder('message_success',$mess);
}
return true;
} // end createDatabaseEntry

$user = $modx->newObject('modUser');
/* set user fields here */
$profile = $modx->newObject('modUserProfile');
/* set profile fields here */
$user->addOne($profile);
$user->save();

[2014-02-25 21:49:43] (WARN @ /index.php) Foreign key definition for class , alias ContractBudget not found, or cardinality is not 'one'. [2014-02-25 21:49:43] (WARN @ /index.php) Could not add related object! Array ( [id] => [created] => 2014-02-25 21:49:43 [modified] => [budget_type_id] => 2 [contract_id] => [budget_f1] => 99.99 [budget_f2] => 99.99 [comment] => [nospam:blank] => [requester_uid] => 1 [program_id] => 1 [status_id] => 2 [location_id] => 9 [client_id] => 3 [employer_id] => 3 [start_balance_f1] => 999.99 [start_balance_f2] => 999.99 [start_date] => 2014-02-05 [end_date] => 2014-02-07 [submit] => [nospam] => )
$tvs = array();
$tv = $modx->newObject('modTemplateVar');
$template = $modx->newObject('modTemplate');
$tvs[] = $tv;
$template->addMany($tvs);
The schema looks very good to me. I think you may be using addOne() where you should be using addMany(). If there can be more than one of what you're adding, addMany() is correct, even if you're just adding one. Here's an example:
$tvs = array(); $tv = $modx->newObject('modTemplateVar'); $template = $modx->newObject('modTemplate'); $tvs[] = $tv; $template->addMany($tvs);