<p>We may need a bit more info to properly debug this, but I wanted to offer some advice and context surrounding the structure of the loop and fetching data so we can at least make sure we're examining the right content!</p>
<p>My suspicion is that this is just a limitation of Craft or PHP's serialization capability, and it's discarding field values that are prepared natively as <code>ElementQuery</code> objects. For performance reasons, Craft doesn't attempt to automatically load every relationship you've defined on an Entry (or Asset, or Matrix Block, etc)—instead, your relational fields are presented as a set of criteria for fetching the related content, and you're responsible for calling <code>.one()</code> or <code>.all()</code> to execute those queries.</p>
<p>When I dump an Entry object, I to see <code>null</code> values for my relational fields. </p>
<p>In your example (as best I can tell), <code>entryItem</code> and <code>menuEntryItem</code> will end up being the same Entry object, just loaded twice in different ways. Check out this alternative means of loading the data:</p>
<pre><code>{# Load Menu Item matrix blocks (replacing `myBlockTypeHandle` with your block type's handle), and &quot;eager-load&quot; the destination Entries (`entryDestination`) and their thumbnail Asset (`entryThumbnail`): #}
{% set menuItems = entry.entrySubMenu.with([
  ['myBlockTypeHandle:entryDestination.entryThumbnail']
]).all() %}

{# Loop over the blocks (you can add the `if` statement back, if you like—this won't output anything if there are no blocks): #}
{% for item in menuItems %}
  {# Access the &quot;first&quot; related destination Entry—we already loaded it, so it should just be an array of everything attached to that field! #}
  {% set destination = item.entryDestination | first %}

  {# Same deal, we've already eager-loaded the nested `entryThumbnail` Asset(s), so we can just grab the first one: #}
  {% image = destination.entryThumbnail | first %}

  {# You could also {% dd image %} or {% dd destination %} if you want to examine either object! #}
  {{ image.getUrl() }}
{% endfor %}
</code></pre>
<blockquote>
<p>The use of <code>| first</code> here is sort of confusing—all relational fields assume there can be multiple results, so they're returned as arrays when eager-loading. This filter just lets us safely access the first one (or returns <code>null</code> if the list is empty).</p>
</blockquote>
<p>So, even though we may not be any not closer to definitively answering your question about the <code>null</code> values in the <code>dd</code> output, I hope this helps you narrow down your debugging!</p>

CC BY-SA 4.0
2022-01-18T23:20:56.083Z
2022-01-18T23:20:56.083Z
August Miller
<p>I am relatively new to Craft CMS and I have encountered an issue that I have attempted to debug for quite some time.</p>
<p>When using the {% dd %} function to dump my array, a load of my custom fields display as 'null' apart from the plain text fields.</p>
<p>The custom field that I am looking at returning is <strong>'entryThumbnail'</strong></p>
<p>Below is the dump of array data:</p>
<pre><code>'customFields' =&gt; craft\behaviors\CustomFieldBehavior#2
    (
        [owner] =&gt; craft\elements\Entry#1(...)
        [yii\base\Behavior:_attachedEvents] =&gt; []
        [hasMethods] =&gt; false
        [canSetProperties] =&gt; false
        [contentBlockOne] =&gt; null
        [contentBuilder] =&gt; null
        [entryHeader] =&gt; null
        [entryThumbnail] =&gt; null
        [imageSlider] =&gt; null
        [menus] =&gt; null
        [navigation] =&gt; null
        [pageVideo] =&gt; null
        [seoDescription] =&gt; 'TEST'
        [seoImage] =&gt; null
        [seoKeywords] =&gt; 'ANOTHER TEST'
        [seoTitle] =&gt; 'TITLE TEST'
        [destinationUrl] =&gt; null
        [destinationEntry] =&gt; null
        [label] =&gt; null
        [menuLabel] =&gt; null
        [menuEntries] =&gt; null
        [slideImage] =&gt; null
        [slideTitle] =&gt; null
        [slideCaption] =&gt; null
        [blockBackgroundColour] =&gt; null
        [blockConfiguration] =&gt; null
        [textBlock] =&gt; null
        [imageBlock] =&gt; null
        [entrySubMenu] =&gt; null
        [entryDestination] =&gt; null
        [craft\behaviors\CustomFieldBehavior:_customFieldValues] =&gt; []
    )
</code></pre>
<p>Here is my code that I have written (Looping through a matrix field with the handle 'entrySubMenu') and then attempting to return custom field data of an entry field in the matrix.</p>
<pre><code>{% set menuItems = entry.entrySubMenu.all() %} 

{% if menuItems|length %} 

        {% for menuEntry in menuItems %}

            {% set menuEntryItem = menuEntry.entryDestination.one() %}

            {% set entryItem = craft.entries().id(menuEntryItem.id).one() %}

            {% dd entryItem %}

        {% endfor %}

{% endif %}
</code></pre>

<templating><assets><matrix><array>
Asset Custom Field Returning Null in Array
# Asset Custom Field Returning Null in Array

(Asked by: username_0 on 2022-01-18)

I am relatively new to Craft CMS and I have encountered an issue that I have attempted to debug for quite some time.
When using the {% dd %} function to dump my array, a load of my custom fields display as 'null' apart from the plain text fields.
The custom field that I am looking at returning is 'entryThumbnail'
Below is the dump of array data:
'customFields' => craft\behaviors\CustomFieldBehavior#2
    (
        [owner] => craft\elements\Entry#1(...)
        [yii\base\Behavior:_attachedEvents] => []
        [hasMethods] => false
        [canSetProperties] => false
        [contentBlockOne] => null
        [contentBuilder] => null
        [entryHeader] => null
        [entryThumbnail] => null
        [imageSlider] => null
        [menus] => null
        [navigation] => null
        [pageVideo] => null
        [seoDescription] => 'TEST'
        [seoImage] => null
        [seoKeywords] => 'ANOTHER TEST'
        [seoTitle] => 'TITLE TEST'
        [destinationUrl] => null
        [destinationEntry] => null
        [label] => null
        [menuLabel] => null
        [menuEntries] => null
        [slideImage] => null
        [slideTitle] => null
        [slideCaption] => null
        [blockBackgroundColour] => null
        [blockConfiguration] => null
        [textBlock] => null
        [imageBlock] => null
        [entrySubMenu] => null
        [entryDestination] => null
        [craft\behaviors\CustomFieldBehavior:_customFieldValues] => []
    )

Here is my code that I have written (Looping through a matrix field with the handle 'entrySubMenu') and then attempting to return custom field data of an entry field in the matrix.
{% set menuItems = entry.entrySubMenu.all() %} 

{% if menuItems|length %} 

        {% for menuEntry in menuItems %}

            {% set menuEntryItem = menuEntry.entryDestination.one() %}

            {% set entryItem = craft.entries().id(menuEntryItem.id).one() %}

            {% dd entryItem %}

        {% endfor %}

{% endif %}

**Tags:** templating, assets, matrix, array


---

## 1 answers

### Answer by username_1 on 2022-01-18. Score: 1

We may need a bit more info to properly debug this, but I wanted to offer some advice and context surrounding the structure of the loop and fetching data so we can at least make sure we're examining the right content!
My suspicion is that this is just a limitation of Craft or PHP's serialization capability, and it's discarding field values that are prepared natively as ElementQuery objects. For performance reasons, Craft doesn't attempt to automatically load every relationship you've defined on an Entry (or Asset, or Matrix Block, etc)—instead, your relational fields are presented as a set of criteria for fetching the related content, and you're responsible for calling .one() or .all() to execute those queries.
When I dump an Entry object, I to see null values for my relational fields. 
In your example (as best I can tell), entryItem and menuEntryItem will end up being the same Entry object, just loaded twice in different ways. Check out this alternative means of loading the data:
{# Load Menu Item matrix blocks (replacing `myBlockTypeHandle` with your block type's handle), and "eager-load" the destination Entries (`entryDestination`) and their thumbnail Asset (`entryThumbnail`): #}
{% set menuItems = entry.entrySubMenu.with([
  ['myBlockTypeHandle:entryDestination.entryThumbnail']
]).all() %}

{# Loop over the blocks (you can add the `if` statement back, if you like—this won't output anything if there are no blocks): #}
{% for item in menuItems %}
  {# Access the "first" related destination Entry—we already loaded it, so it should just be an array of everything attached to that field! #}
  {% set destination = item.entryDestination | first %}

  {# Same deal, we've already eager-loaded the nested `entryThumbnail` Asset(s), so we can just grab the first one: #}
  {% image = destination.entryThumbnail | first %}

  {# You could also {% dd image %} or {% dd destination %} if you want to examine either object! #}
  {{ image.getUrl() }}
{% endfor %}


The use of | first here is sort of confusing—all relational fields assume there can be multiple results, so they're returned as arrays when eager-loading. This filter just lets us safely access the first one (or returns null if the list is empty).

So, even though we may not be any not closer to definitively answering your question about the null values in the dd output, I hope this helps you narrow down your debugging!


---

