Entries object getting reset after a relatedTo query This is from a template that worked in Craft 2, but doesn't in Craft 3.

{% set entries = craft.entries.type('publications').orderBy("postDate desc") %}


entries.count() outputs 80

{% for cat in allCats %}
    {% set catEntries = entries.relatedTo(cat) %}
    {% if catEntries | length or cat.slug=="all" or cat.slug=="toutes" %}
        &lt;li&gt;&lt;a href="{{ cat.url }}" {% if category is defined and cat.slug == category.slug %}class="current"{% endif %}&gt;{{ cat.title }}&lt;/a&gt;&lt;/li&gt;
    {% endif %}
{% endfor %}


This iterates through all categories with correct entries associated

After that, entries.count() outputs 0

Looks like entries is getting set to the last value instead of just passing the resulting object to the variable.  This is not how it worked before.  Is there a way to reset this ?
Based on the bug report found here (https://github.com/craftcms/cms/issues/2160), I am now creating a variable that contains all of the items prior to filtering it.

{% set entries = craft.entries.type('publications').orderBy("postDate desc") %}
{% set allEntries = entries.all() %}


I can then use entries to filter through the available categories and then use allEntries to loop through all of them.

I understand I could also have used clone() to get a copy to work from in my category loop. 

{% set catEntries = clone(entries).relatedTo(cat) %}