4

I am trying to eager load users in a specific group to reduce queries. I've tried this:

                {% set designers = craft.users({
                    group: 'designers',
                    with: [
                            'userAgencyName',
                            'userAgencyUrl',
                            'userFreelancerAgency',
                            'userDescriptionServices',
                            'userBudget',
                            'userCity',
                            'userStateProvince'
                            ]
                }) %}

This consists of 5 user text fields and 2 user category fields. Although it's returning the array to string conversion error.

The loop is setup like this:

    {% paginate designers.limit(7) as designers %}

    {# Loop through Designers #}
    {% for designer in designers %} 

    <div class="listing-box">
        <h1><a href="/designers/{{ designer.username }}">{{ designer.userAgencyName }}</a></h1>

        <div class="listing-links">
            <ul>
                <li>
                {% for category in designer.userFreelancerAgency %}
                <a href="{{ category.url }}"> {{ category }}</a>
                {% endfor %}    
                </li>
                {% for category in designer.userBudget %}
                {% if category %}
                <li>                    
                Budgets: <a href="{{ category.url }}">{{ category }}</a>                    
                </li>
                {% endif %}
                {% endfor %}
                {% if designer.userCity | length %}     
                <li>{{ designer.userCity }}, {{ designer.userStateProvince }}</li>
                {% endif %}
            </ul>
        </div>  
        <p>{% if designer.userDescriptionServices %}{{ designer.userDescriptionServices }}{% endif %} 

    </div>
    <!--End listing-box-->  
   {% endfor %} 

Thanks in advance for any help you can give!

Angela
  • 569
  • 2
  • 12
  • I think this may be because you are eager-loading text fields, try to remove them from your with and then reload template. – mcclaskiem Apr 07 '16 at 19:47

1 Answers1

5

Just checked eager-loading a text field in a template and by eager-loading it you are actually converting the field to an array and therefore unable to template it as usual. Eager-loading is generally only useful on fields like categories, assets, and matrixes.

mcclaskiem
  • 677
  • 3
  • 14
  • Thanks! You are right. Removing the text fields worked. Eager loading the categories (and one asset field I will be adding) should help. :) – Angela Apr 07 '16 at 20:01
  • 1
    Don't forget to eager load the transforms as well if your asset field is using image transforms! – Patrick Harrington Apr 08 '16 at 00:13