Clear SQL in relations.
Extract Query#ids method.