Hi again,
I can't get the saveAll() method to work for an indirectly-associated
model. My model associations are:
Clon hasMany MotherClon
Clon hasMany FatherClon
Mated belongsTo Mother /* mated.mother_id -> clon.id */
Mated belongsTo Father /* mated.father_id -> clon.id */
Mated belongsTo Pop /* mated.pop_id -> pop.id */
Pop hasMany Mated
So, what I'm trying to do is save a new Pop record, save 0, 1 or 2
Clon records, THEN add the appropriate record to the linking Mated
table (I view the problem this way because I don't see how I can add
the foreign keys mother_id and father_id into a Mated record before
they exist in Clon). And I cannot get the Clon data saved from the
pops_controller. I have been all over the web and cannot see how my
approach differs from anything that I have read.
Code snippets follow. I have gone brain-dead and am completely lost
here, any suggestions?
Thanx, DaveT.
/////////////// from pops_controller.php:
function add() {
$this->loadModel('Clon');
// also tried: $Clon = ClassRegistry::init('Clon');
if (array_key_exists('Cancel', $this->params['form'])) {
$this->Session->setFlash('Cancelled adding new population.');
$this->redirect(array('action'=>'index'));
} elseif (!empty($this->data)) {
$this->Pop->create();
if ($this->Pop->saveAll($this->data['Pop'],
array('validate'=>'first')) {
// also tried: $this->Pop->saveAll($this->data['Clon'],
array('validate'=>'first'))
$this->Session->setFlash('The Population has been
saved.');
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash('The Population could not be
saved.
Please, try again.');
}
}
} // end add()
/////////////// from pops\add.ctp:
echo $form->input('id');
echo $form->input('Clon.id');
echo $form->input('name', array( 'label' => 'Population' ));
echo $form->input('Clon.1.name', array( 'label' => 'Mother' ));
echo $form->input('Clon.2.name', array( 'label' => 'Father' ));
// echo $form->input( <other pop fields> );
Check out the new CakePHP Questions site http://cakeqs.org and help others with
their CakePHP related questions.
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en