Fix a bug in query builder which was not correctly resetting the were condition when existing resource id was changing.