I'm confused about what to pass as a parameter in the descendantOf() function. I'm developing a website and passing an entry ID as a string (I also tested it as an integer) and everything went fine, untill now. Suddenly, when I try to use it with new template code, that doesn't work anymore. It does however still work in my template I wrote last week.
The docs say that the parameter has to be an EntryModel:
descendantOf #
Only fetch categories that are a descendant of a given category. Accepts a CategoryModel object.
In this thread on SE, someone says it can be an Entry ID.
descendantOf accepts either an EntryModel object or an entry’s ID.
However, if I use the next code (category is not a category group, I'm using a structure for it) where currentRegionId is an entryId as a string or integer:
{% for productCategory in product.productCategory.descendantOf(currentRegionId).order("title asc").find() %}
This works. But according to the docs, it shouldn't work, because I'm passing an ID and not an EntryModel.
It also works when I pass that ID while using eager loading:
{% set mainCategories = craft.entries({
section: 'productCategories',
level: 2,
descendantOf: currentRegionId,
limit: null,
with: ['productCategoryIcon']
}) %}
However, if I try the next piece of code in another template:
{% for category in entry.applyToCategories if category.descendantOf(currentRegionId) %}
I get this error:
Argument 1 passed to Craft\BaseElementModel::isDescendantOf() must be an instance of Craft\BaseElementModel, integer given
If I pass an EntryModel it does work as expected and according with the docs:
{% for category in entry.applyToCategories if category.descendantOf(craft.entries.id(currentRegionId).first()) %}
So what's going on? Is it something with the way I fetch my entries?