Term relationship query bugfix