Added fix for NoneType forigen relations