Hi,
This is probably going to be a fairly obvious fix, but its got me
stumped.
I have 2 tables users and counsellors.
The counsellors table is associated with the users table (belongsTo)
and the users table to counsellors via hasOne.
What i want to achieve is to have a user automatically created (on the
same form as the counsellors) when a new counsellor is added...
(getLastInsertId didnt work and i found a fix for it on this group)
counsellors controller code:
<?php
class CounsellorsController extends AppController
{
var $name = 'Counsellors';
//var $scaffold;
function index()
{
$this->set('counsellors', $this->Counsellor->findAll());
}
function view($id = null)
{
$this->Counsellor->id = $id;
$this->set('counsellor', $this->Counsellor->read());
}
function add()
{
if (!empty($this->data))
{
//getLastInsertId fix
$temp = $this->Counsellor->User->execute("SELECT LAST_INSERT_ID()
from users");
print_r($temp);
$last_insert = $temp[0][0]['LAST_INSERT_ID()'];
$user_id=$last_insert+1;
$this->params['data']['Counsellor']['user_id'] = $user_id;
print_r($this->data);
$this->Counsellor->User->save($this->params['data']['User']);
if ($this->Counsellor->save($this->data))
{
$this->flash('Your new Counsellor has been
saved.','/counsellors');
}
}
}
}
?>
any help on this would be great, from what i read in the manual it sais
that cake will automatically save data to associated tables if the
correct ID is passed but i'm passing it the (potential next 'id' (in
the users table) as user_id (correct naming convention) and it isnt
populating the rest of the data passed over (username password etc).
Cheers, Quentin.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" 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
-~----------~----~----~----~------~----~------~--~---