Fixed build_nested_query to handle hashes whose values are empty arrays