I have two models - Rotas and Lines.
Rotas have many lines and Lines belongs to Rotas. I am trying to
create a function that will take an existing record (a rota with n
lines) and save it as a new rota complete with the associated lines.

I can create a new rota and add new lines, I can create a new rota
based on an existing one but with no lines.

I am aware of unsetting the id to force an add but cannot seem to
bring the associated lines with it. I have scoured the forums and have
been bashing this one for 2 weeks now - can anyone give me a clue?

The first part of the function creates a new rota record but the
second part creates nothing (trying to savas existing lines).

I have also tried getLastInsertID() but cannot seem to get a value
from this.

I think my basic principle is wrong!

function copyLast($id = null) {

$this->Rota->recursive = 2;
unset( $this->data['Rota']['id'] );

if ($this->Rota->save($this->data)) {

if (!empty($this->data)) {
                        $this->data = $this->Rota->read(null, $rota_id);
                        $tempData = $this->data['Line'];

                        foreach($tempData as $id => $value)
                                {
                                        unset( $this->data['Line'][$id]['id'] );
                                        unset( 
$this->data['Line'][$id]['rota_id'] );
                                        unset( 
$this->data['Line'][$id]['Rota']['id'] );
                                        $this->Rota->Line->create();
                                        $this->Rota->Line->save($this->data);
                                }
                }
}

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to