<p>The keyword when it comes to &quot;eager-loading elements&quot; is <em>elements</em>. In Craft parlance, an element type is one of Assets, Categories, Entries, etc. See the <a href="https://craftcms.com/docs/4.x/elements.html" rel="nofollow noreferrer">definition of elements</a>.</p>
<p>As per the <a href="https://craftcms.com/docs/4.x/dev/eager-loading-elements.html" rel="nofollow noreferrer">docs</a>:</p>
<blockquote>
<p>The purpose of the <code>with</code> param is to tell Craft which sub-elements you’re going to be needing in advance, so that it can fetch them all up front, in as few queries as possible.</p>
</blockquote>
<p>So it only makes sense to use the <code>with</code> parameter with custom fields that are <a href="https://craftcms.com/docs/4.x/relations.html" rel="nofollow noreferrer">relational field types</a> (Assets, Categories, Entries, etc.) that return sub-elements, in addition to matrix blocks and image transform indexes.</p>
<p>All other custom fields (with the possible exception of those added by third-party plugins) don't require eager-loading, as they are available directly on the populated element.</p>

CC BY-SA 4.0
2022-09-12T18:11:03.287Z
2022-09-12T21:00:32.393Z
2022-09-12T21:00:32.393Z
Ben Croker
<p>I'm testing the DB queries required for a Craft query and I realized that adding the title field to the eager loading doesn't change anything. So it seems like the title is retrieved by default.</p>
<p>Means:</p>
<pre><code>{% set entries = craft.entries.section('whatever').relatedTo(tag).with([
    'customField'
]).all() %}
</code></pre>
<p>Has the same performance than:</p>
<pre><code>{% set entries = craft.entries.section('whatever').relatedTo(tag).with([
    'title',
    'customField'
]).all() %}
</code></pre>
<p>So, my assumption is that I need to provide only custom fields created by myself for the entry, when eager loading queries.</p>
<p>I didn't find this information in <a href="https://craftcms.com/docs/4.x/dev/eager-loading-elements.html" rel="nofollow noreferrer">the docs</a>.</p>

<queries><eager-loading>
What fields are eager loaded by default in Craft Queries?
# What fields are eager loaded by default in Craft Queries?

(Asked by: username_0 on 2022-09-12)

I'm testing the DB queries required for a Craft query and I realized that adding the title field to the eager loading doesn't change anything. So it seems like the title is retrieved by default.
Means:
{% set entries = craft.entries.section('whatever').relatedTo(tag).with([
    'customField'
]).all() %}

Has the same performance than:
{% set entries = craft.entries.section('whatever').relatedTo(tag).with([
    'title',
    'customField'
]).all() %}

So, my assumption is that I need to provide only custom fields created by myself for the entry, when eager loading queries.
I didn't find this information in the docs.

**Tags:** queries, eager-loading


---

## 1 answers

### Answer by username_1 on 2022-09-12. Score: 2 | Accepted answer

The keyword when it comes to "eager-loading elements" is *elements*. In Craft parlance, an element type is one of Assets, Categories, Entries, etc. See the [definition of elements](https://craftcms.com/docs/4.x/elements.html).

As per the [docs](https://craftcms.com/docs/4.x/dev/eager-loading-elements.html):

> The purpose of the `with` param is to tell Craft which sub-elements you’re going to be needing in advance, so that it can fetch them all up front, in as few queries as possible.

So it only makes sense to use the `with` parameter with custom fields that are [relational field types](https://craftcms.com/docs/4.x/relations.html) (Assets, Categories, Entries, etc.) that return sub-elements, in addition to matrix blocks and image transform indexes.

All other custom fields (with the possible exception of those added by third-party plugins) don't require eager-loading, as they are available directly on the populated element.


---

