fix null reference exception when id field for a foreign field can't be determined