Fixed bug - check that the foreign key has a valid ID