I'm trying to find all tiers that have associated entries for a selection dropdown.
This does not work, and throws a 502 error
{% set allTeirs = craft.categories.group('catPartnerTeirs') %}
{% set partnersWithTeirs = allPartnerEntries.relatedTo(allTeirs).limit(null) %}
{% set partnerTeirsInUse = allTeirs.relatedTo(partnersWithTeirs).all() %}
This does work, but results in duplicate DB queries:
{% set allTeirs = craft.categories.group('catPartnerTeirs') %}
{% set partnersWithTeirs = allPartnerEntries.relatedTo(allTeirs).limit(null) %}
{% set partnerTeirsInUse = craft.categories.group('catPartnerTeirs').relatedTo(partnersWithTeirs).all() %}
Can someone explain to me why? I've dumped them both to the page (the set variable and the query itself and they both return exactly the same object, so far as I can tell.
I'm also totally open to better ways of finding "Tiers that have associated entries", if you've got that too.
allPartnerEntries
so we can see what that looks like?allTeirs
should be a list of categories,allPartnerEntries
should return a list of entries,partnerTeirsInUse
should return a list of categories (possibly shorter thanallTeirs
). What do you get?