Iterating through ResultSet causes another query

Hi all,

I'm creating a ResultSet by calling

$this->view->all_locations = \Model\Location::find(['order'=>'name asc']);

In my Volt file, I'm iterating through that resultset with this code

<select class = "selectpicker col-xl-8 col-md-6 col-xs-12 m-b" multiple id = "location-picker">
    {% for Location in all_locations %}
        {% if !Location.hidden %}
            <option value = "{{ }}" {% if viewing_locations is not NULL AND ( in viewing_locations) %}selected{% endif %}>{{ }}</option>
        {% endif %}
    {% endfor %}

This code is causing a second identical query to be executed - and I have no idea why.

edited Dec '15

I think I've had something similar. I'm not sure though it was exactly same additional query, just remember that view loading speed dropped several times after a replaced simple php iteration through resultset with volt syntax. And it resolved when I replaced volt syntax iterator with simple php itterator again.

The interesting thing is that I have left all other things in view volt syntaxed and I saw this behaviour of volt's for only in one particular view.


Look at the compiled view in the view cache directory to see what the PHP is. Then extract this into an controller or task action.