Fix null reference exception.
Check for related models correctly.