bug fix to relations with where clauses