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


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to