[eluser]OverZealous[/eluser]
[quote author="NachoF" date="1269538999"]
I want to save it all at once cause its all coming from the same form.[/quote]
You have to save each new object one-by-one. You also have to save relationships on the object as they exist.
However, if you wrap them all in a transaction, you can rollback the saves if something goes wrong. (Even when DMZ saves multiple relationships, it doesn't automatically wrap them in a transaction — if something failed, it would not automatically roll back the first items saved.)
Code:
$project->trans_begin();
// if new: save $region, $function, or $organization, too
$success = $stage->save(array($region, $function, $organization));
if($success) {
$success = $project->save($stage);
}
if($success) {
$project->trans_commit();
$this->session->set_flashdata('success', 'Project Created');
redirect("Welcome");
} else {
$project->trans_rollback();
// show error, etc.
}
* Note: you need a transactionable table type if you are using MySQL.