Answers.Body: <p>These are two different things.</p>
  
  <pre><code>{% set entries = myEntryModel.myEntriesField.descendantOf(var) %}
  </code></pre>
  
  <p>In this case the Entries field returns an <code>ElementCriteriaModel</code> object and you are setting the <a href="https://craftcms.com/docs/templating/craft.entries#descendantOf" rel="nofollow noreferrer"><code>descendantOf</code></a> parameter, which does in fact accept <code>EntryModel</code> objects or an Entry ID as an integer value. The Craft documentation is incomplete in this regard.</p>
  
  <pre><code>{% set bool = myEntryModel.isDescendantOf(var) %}
  </code></pre>
  
  <p>Here you are using the method <a href="https://craftcms.com/docs/templating/entrymodel#isDescendantOf" rel="nofollow noreferrer"><code>isDescendantOf</code></a> that is available for an <code>EntryModel</code> and returns whether the entry is a descendant of another entry. This method apparently only accepts an <code>EntryModel</code>.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-25T15:45:19.577Z
Answers.Text: Looks like a solid explanation! Thanks. That'll be it I guess.
Answers.UserDisplayName: Tom De Smet
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-25T14:07:52.903Z
Answers.LastActivityDate: 2017-04-25T14:07:52.903Z
Answers.UserDisplayName: carlcs
Body: <p>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.</p>
  
  <p>The <a href="https://craftcms.com/docs/templating/craft.categories#descendantOf" rel="nofollow noreferrer">docs say</a> that the parameter has to be an EntryModel:</p>
  
  <blockquote>
    <p>descendantOf #</p>
    
    <p>Only fetch categories that are a descendant of a given category.
    Accepts a CategoryModel object.</p>
  </blockquote>
  
  <p>In <a href="https://craftcms.stackexchange.com/questions/1298/how-can-i-get-the-count-of-entries-in-a-structure">this thread</a> on SE, someone says it can be an Entry ID.</p>
  
  <blockquote>
    <p>descendantOf accepts either an EntryModel object or an entry’s ID.</p>
  </blockquote>
  
  <p>However, if I use the next code (category is not a category group, I'm using a structure for it) where <code>currentRegionId</code> is an entryId as a string or integer:</p>
  
  <pre><code>{% for productCategory in product.productCategory.descendantOf(currentRegionId).order("title asc").find() %}
  </code></pre>
  
  <p>This works. But according to the docs, it shouldn't work, because I'm passing an ID and not an EntryModel.</p>
  
  <p>It also works when I pass that ID while using eager loading:</p>
  
  <pre><code>{% set mainCategories = craft.entries({
      section:            'productCategories',
      level:              2,
      descendantOf:       currentRegionId,
      limit:              null,
      with:               ['productCategoryIcon']
  }) %}
  </code></pre>
  
  <p>However, if I try the next piece of code in another template:</p>
  
  <pre><code>{% for category in entry.applyToCategories if category.descendantOf(currentRegionId) %}
  </code></pre>
  
  <p>I get this error:</p>
  
  <blockquote>
    <p>Argument 1 passed to Craft\BaseElementModel::isDescendantOf() must be
    an instance of Craft\BaseElementModel, integer given</p>
  </blockquote>
  
  <p>If I pass an EntryModel it does work as expected and according with the docs:</p>
  
  <pre><code>{% for category in entry.applyToCategories if category.descendantOf(craft.entries.id(currentRegionId).first()) %}
  </code></pre>
  
  <p>So what's going on? Is it something with the way I fetch my entries?</p>
  
Tags: <entries><structure><descendantof>
Title: descendantOf() parameter, entryModel or ID?
ThreadText: # descendantOf() parameter, entryModel or ID?
  
  (Asked by: username_0 on 2017-04-25)
  
  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](https://craftcms.com/docs/templating/craft.categories#descendantOf) 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](https://craftcms.stackexchange.com/questions/1298/how-can-i-get-the-count-of-entries-in-a-structure) 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?
  
  **Tags:** entries, structure, descendantof
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-04-25. Score: 2 | Accepted answer
  
  These are two different things.
  
  ```
  {% set entries = myEntryModel.myEntriesField.descendantOf(var) %}
  
  ```
  
  In this case the Entries field returns an `ElementCriteriaModel` object and you are setting the [`descendantOf`](https://craftcms.com/docs/templating/craft.entries#descendantOf) parameter, which does in fact accept `EntryModel` objects or an Entry ID as an integer value. The Craft documentation is incomplete in this regard.
  
  ```
  {% set bool = myEntryModel.isDescendantOf(var) %}
  
  ```
  
  Here you are using the method [`isDescendantOf`](https://craftcms.com/docs/templating/entrymodel#isDescendantOf) that is available for an `EntryModel` and returns whether the entry is a descendant of another entry. This method apparently only accepts an `EntryModel`.
  
  > **Comments:**
  > **username_0**: Looks like a solid explanation! Thanks. That'll be it I guess.  
  
  ---
  
  