Fixes for way tables are quoted, optimisations

The table quoting was causing SQL errors with mysql.

The optimisation is to not save the bObject when creating a new relationship
unless it has not been inserted, and to not create new relationships if they
already exists in the list.  I guess this is more of a bug-fix than an optimisation,
but it certainly helps optimise!