Fixes problem with multiple foreign keys to the same table.