We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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 = "{{ Location.id }}" {% if viewing_locations is not NULL AND (Location.id in viewing_locations) %}selected{% endif %}>{{ Location.name }}</option>
        {% endif %}
    {% endfor %}
</select>

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.