[4.x] Eager loaded elements are null #12247
-
Hey, not sure if this is a bug or an issue on our side so a discussion rather then an issue. We have quite a complicated page with some filtering, relations etc. where we have a problem with eager loading of an entries field. Even if I simplify the query the problem is the same. {% set newsQuery = craft.entries.section('news').with(['heroImage', 'topics', 'category']).limit(4).all() %}
{% for news in newsQuery %}
{{ d(news.topics.one()) }}
{% endfor %} The result of the dump is Any hint on what might be the problem here and what I could look at? Thanks. EDIT: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Edit because I was wrong. Since Craft 4, eager loaded elements are returned as an The (mostly) original answer below still applies to Craft 3 though. You'll need to use the array syntax when accessing eager loaded elements.
|
Beta Was this translation helpful? Give feedback.
Edit because I was wrong.
Since Craft 4, eager loaded elements are returned as an
craft\elements\ElementCollection
which doesn't care if you use[0]
or.one()
.The (mostly) original answer below still applies to Craft 3 though.
You'll need to use the array syntax when accessing eager loaded elements.