updated trigger so that it checks that entities exist before making an entity relationship deactivation event