Wouldn't be better to make use of validators [1]? This way you can assure that all foreign key constrains are fulfilled
[1] http://www.symfony-project.com/book/trunk/10-Forms#Form%20Validation Cheers, Marc 2007/8/1, Michael Smith <[EMAIL PROTECTED]>: > > > You have to pares the exception message to determine if it was a > foreign key and which one it was. I wish there was a cleaner way of > doing it but the function below works for mysql at least. > > /** > * Parses out the table, field, and error message from a foreign > key > failure > * > * @param PropelException $e > * @param array $retArray > * @return bool true if there was a fk failure > */ > public static function parseForeignKeyException(PropelException $e, & > $retArray){ > if(strstr($e->getMessage(), 'a foreign key constraint fails')){ > $con = Propel::getConnection(); > $dsn = $con->getDSN(); > > preg_match('|'. $dsn['database'] . '/(.+?)`|', > $e->getMessage(), > $matches); > $retArray['table'] = $matches[1]; > preg_match('|FOREIGN KEY \(`(.+?)`\)|', $e->getMessage(), > $matches); > $retArray['field'] = $matches[1]; > $retArray['message'] = $e->getMessage(); > return true; > }else{ > return false; > } > } > > > On Jul 31, 7:02 pm, Greg Freeman <[EMAIL PROTECTED]> wrote: > > Is there any way to determine which foreign key has denied an insert/ > > update? (for error handling issues) The only example I have found is: > > > > try > > { > > $obj->save();} > > > > catch (PropelException $e) > > { > > // error handling > > > > } > > > > I would like to be able to determine which foreign key caused the > > exception so I can have a custom error for each. > > > > Thanks > > > > > -- "Beware of bugs in the above code; I have only proved it correct, not tried it." Donald Knuth --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---