I assume you are using doctrine.  You may want to try setting a
relationship i.ie:

function doSave(){
   $client->Logs[] = $log;
   $client->save();
}

that should save the client first and then add the log (assuming the
client is not already in the db) and save the log.
You could also do it more explicity like, but the same thing happens
with the last bit of code, although it takes place behind the scenes:

function doSave(){
  $client->save();
  $log = new Log();
  $log->client_id = $client->id;
}

hth,
Casey

On May 3, 8:02 pm, Abraham <[email protected]> wrote:
> Hi Guys, i have two tables: Client and Log, Log has a simple foreign
> key to Client. A client belongs to an user in time, so the Log table
> saves who has the client actually.
>
> i'm saving Clients normally with a form, but i also want to save in
> the log accordingly through this way:
>
> protected function doSave($con = null) {
>
>     $log_client_user = new Log();
>
>     $log_client_user->set('Client_id', $this->values['id']);
>     $log_client_user->set('User_code',$this->values['User_code']);
>     $log_client_user->set('date_acquired',$this-
>
> >values['date_created']);
>
>     $log_client->save();
>
>     return parent::doSave($con);
>   }
>
> however, a foreign key constraint error shows up. So how can i do
> something like first saving the client and then saving the log in
> short steps?
>
> i also tried using this for the foreign key:
>
> $log_client_user->set('Client_id', $this->getObject());
>
> and also
>
> $log_client_user->setClientId($this->getObject());
>
> but none of them worked because $this->getObject() is still null in
> the doSave() function. By the way, the save() fuction has the same
> problem.
>
> Can you hrlp me, please? Thanks in advance!
>
> --
> If you want to report a vulnerability issue on symfony, please send it to 
> security at symfony-project.com
>
> You received this message because you are subscribed to the Google
> Groups "symfony users" 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 
> athttp://groups.google.com/group/symfony-users?hl=en

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony users" 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/symfony-users?hl=en

Reply via email to