6

In looking at the the BaseElementModel:getDescendants() method and saw it checks for eager loading elements named 'descendants.'

// Eager-loaded?
if ($this->hasEagerLoadedElements('descendants'))
{
    return $this->getEagerLoadedElements('descendants');
}

I added with and the descendants condition to a Structure and the page is now loading with a few less queries.

{% set entries = craft.entries({
    section: 'sectionHandle',
    limit: null,
    with: [
        'descendants'
    ]
}) %}

Can anybody explain what is happening here?

7

Craft 2.6.2789 added this feature, which is seems you've reverse engineered. :)

It is now possible to eager-load Structure entries' and categories' descendants using the 'descendants' handle.

| improve this answer | |
  • Easy points! And I see I should have searched the changelog, not the docs ;-) – Ben Parizek Jun 29 '16 at 0:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.