I am trying to add eager loading to a query. The original query was as follows (‘sticky’ is a custom lightswitch field for marking sticky entries):
{% set news = craft.entries.section('news').order('sticky desc, postDate desc').limit(9) %}
Is the following ok syntax for adding eager loading?
{% set news = craft.entries.section('news').order('sticky desc, postDate desc').limit(9).find({
with: [
['newsHighlightImage', {
withTransforms: ['newsMedium', 'newsSmall']
}]
]
}) %}
I ask because although the above seems to work, in the examples in the documentation, the find/with bits come right after the section parameter. But if I do it that way, I get an error about not being able to apply the “order” method. I reckon that’s because find() turns the result into an array so “order” is not longer available. But I couldn’t figure out the correct carry syntax to make it work that way. Is there a better way to do this?
Thanks!
Willhaus