<p>Actually it was as simple that Craft 5 migration automatically renamed some fields that had the same handle in matrixes. (fieldName<strong>2</strong> for example). So renaming in code and field type in control panel and making sure everything matches, fixed this.</p>

CC BY-SA 4.0
2024-06-05T09:43:04.910Z
2024-06-05T09:43:04.910Z
Tibbe
<p>Im trying to query a list of matrix entries that have a related field but it doesn't work after updating to craft 5. Note that 'category' is not category field type, its a regular structured entry type.</p>
<pre><code>{% set relatedDetails = entry.details
    .type('customDetails')
    .relatedTo({
        targetElement: block.category.one(),
        field: 'category'
    })
    .all()
%}
</code></pre>
<p>returns 0 elements. However:</p>
<pre><code>{% set unassignedDetails = entry.details.category(':empty:').all()%}
</code></pre>
<p>this works as intended, returning all nested entries that does not have that field assigned.</p>
<p>How can I do it?</p>

<matrix><relatedto><nested>
relatedTo craft 5 nested matrix entires
# relatedTo craft 5 nested matrix entires

(Asked by: username_0 on 2024-06-05)

Im trying to query a list of matrix entries that have a related field but it doesn't work after updating to craft 5. Note that 'category' is not category field type, its a regular structured entry type.
{% set relatedDetails = entry.details
    .type('customDetails')
    .relatedTo({
        targetElement: block.category.one(),
        field: 'category'
    })
    .all()
%}

returns 0 elements. However:
{% set unassignedDetails = entry.details.category(':empty:').all()%}

this works as intended, returning all nested entries that does not have that field assigned.
How can I do it?

**Tags:** matrix, relatedto, nested

---

## 1 answers

### Answer by username_0 on 2024-06-05. Score: 1

Actually it was as simple that Craft 5 migration automatically renamed some fields that had the same handle in matrixes. (fieldName**2** for example). So renaming in code and field type in control panel and making sure everything matches, fixed this.


---

