Added checking if a relation object is not null in building links