Fix UUID and conversion of foreign key values, fixes #394 with many
thanks to @alexlatchford.