<p>Eager-Loading is not like a hook or a callback. You wouldn't set variables within it. You'd want to use eager-loading to load your <code>eventVenueId</code> then in your loop you'd set the variable a little differently.</p>

<pre><code> {% set entries = craft.entries ({
          section: 'events',
          order: 'postDate desc',
          with: ['eventMainImage', 'eventVenueId'],
          relatedTo: category
  }) %}

 {% for entry in entries %}
    {% set venue = entry.eventVenueId[0] ?? null %}

</code></pre>

<p>Additionally you could look at eager-loading a <a href="https://docs.craftcms.com/v3/dev/eager-loading-elements.html#eager-loading-nested-sets-of-elements" rel="nofollow noreferrer">Nested Set of Elements</a> to further optimize your query if possible with the data you need off your <code>eventVenueId</code> elements.</p>

CC BY-SA 4.0
2019-03-01T20:36:14.023Z
2019-03-01T20:36:14.023Z
Ian
<p>I'm looking to eager load and set another variable within the eager loading. But I can't seem to find out how on numerous guides/tutorials, and the query seems to be slowing the system down a bit.</p>

<pre><code>  {% set entries = craft.entries ({
          section: 'events',
          order: 'postDate desc',
          with: ['eventMainImage'],[''],
          relatedTo: category
      }) %}

  {% for entry in entries %}
    --&gt; {% set venue = entry.eventVenueId.one() %}
</code></pre>

<p>As you can see by the arrow, I'm wanting to set this property, is this possible within an eager load?</p>

<templating><eager-loading>
Set Property within Eager Loading
# Set Property within Eager Loading

(Asked by: username_0 on 2019-03-01)

I'm looking to eager load and set another variable within the eager loading. But I can't seem to find out how on numerous guides/tutorials, and the query seems to be slowing the system down a bit.
  {% set entries = craft.entries ({
          section: 'events',
          order: 'postDate desc',
          with: ['eventMainImage'],[''],
          relatedTo: category
      }) %}

  {% for entry in entries %}
    --> {% set venue = entry.eventVenueId.one() %}

As you can see by the arrow, I'm wanting to set this property, is this possible within an eager load?

**Tags:** templating, eager-loading

---

## 1 answers

### Answer by username_1 on 2019-03-01. Score: 2 | Accepted answer

Eager-Loading is not like a hook or a callback. You wouldn't set variables within it. You'd want to use eager-loading to load your eventVenueId then in your loop you'd set the variable a little differently.
 {% set entries = craft.entries ({
          section: 'events',
          order: 'postDate desc',
          with: ['eventMainImage', 'eventVenueId'],
          relatedTo: category
  }) %}

 {% for entry in entries %}
    {% set venue = entry.eventVenueId[0] ?? null %}


Additionally you could look at eager-loading a Nested Set of Elements to further optimize your query if possible with the data you need off your eventVenueId elements.


---

