fix issue when referencing primary_key in other where clauses