Answers.Body: <p>You were on the right track using <code>relatedTo</code>. But as there's no <code>notRelatedTo</code> parameter, you'd first have to get all drinks that are related to any ingredient and those entries can then be removed from a new ElementCriteriaModel, that returns all your drinks, using Craft's <a href="http://buildwithcraft.com/docs/templating/filters#without" rel="nofollow noreferrer"><code>without</code></a> filter. Instead of passing whole element models, you should better use this filter with element IDs (→ <a href="https://craftcms.stackexchange.com/q/7170/125">Why is the Craft without filter not working correctly and how to debug?</a>). To get them just make use of the <a href="http://buildwithcraft.com/docs/templating/elementcriteriamodel#ids" rel="nofollow noreferrer"><code>ids()</code></a> method.</p>
  
  <pre><code>{% set ingredients = craft.entries.section('ingredients').limit(null) %}
  {% set drinksWithIngredientsIds = craft.entries.section('drinks').relatedTo({targetElement: ingredients}).limit(null).ids() %}
  
  {% set drinksWithNoIngredients = craft.entries.section('drinks')|without(drinksWithIngredientsIds) %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-17T03:08:39.680Z
Answers.Text: Genius! Thanks so much. On a minor note, I had to change the last line to retrieve ids: `{% set drinksWithNoIngredientsIds = craft.entries.section('drinks').ids()|without(drinksWithIngredientsIds) %}` for the `without` filter to kick in. I then was able to get all the entries I wanted via: `craft.entries.id(drinksWithNoIngredientsIds)`.
Answers.UserDisplayName: jx7
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-17T03:10:28.043Z
Answers.Text: Also, out of curiosity, what role does the `.limit(null)` parameter play in the first two lines of code?
Answers.UserDisplayName: jx7
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-17T06:03:48.567Z
Answers.Text: `limit` is set to 100 by default. So it just makes sure you include all the ingredients, last line is for the output and you can limit or paginate to your liking.
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-16T08:44:45.933Z
Answers.LastActivityDate: 2015-04-16T08:50:31.923Z
Answers.LastEditDate: 2017-04-13T12:51:00.253Z
Answers.UserDisplayName: carlcs
Body: <p>I'm new to all this. Is it possible to use <code>craft.entries</code> to return all entries with an empty entries field? Something like:</p>
  
  <pre><code>{% set drinksWithNoIngredients = craft.entries.section("drinks").ingredients(":empty:") %}
  {% for drink in drinksWithNoIngredients %}
      &lt;p&gt;Do something with {{ drink.title }}...&lt;/p&gt;
  </code></pre>
  
  <p>where <code>ingredients</code> is an entries field handle. This doesn't seem to work on entries fields, though. Or maybe I could do some kind of <code>relatedTo</code> magic, where the <code>targetElement</code> is some kind of special null value?</p>
  
  <p>An alternative seems to be this:</p>
  
  <pre><code>{% set drinksWithNoIngredients = craft.entries.section("drinks") %}
  {% for drink in drinksWithNoIngredients %}
      {% if not drink.ingredients.total() %}
      &lt;p&gt;Do something with {{ drink.title }}...&lt;/p&gt;
  </code></pre>
  
  <p>But doing it that way calls <code>.total()</code> on <em>every</em> drink. Is that going to cause performance problems if I have a lot of drinks?</p>
  
Tags: <elementcriteriamodel>
Title: Using craft.entries to return entries with empty entries field
ThreadText: # Using craft.entries to return entries with empty entries field
  
  (Asked by: username_0 on 2015-04-16)
  
  I'm new to all this. Is it possible to use `craft.entries` to return all entries with an empty entries field? Something like:
  
  ```
  {% set drinksWithNoIngredients = craft.entries.section("drinks").ingredients(":empty:") %}
  {% for drink in drinksWithNoIngredients %}
      <p>Do something with {{ drink.title }}...</p>
  
  ```
  
  where `ingredients` is an entries field handle. This doesn't seem to work on entries fields, though. Or maybe I could do some kind of `relatedTo` magic, where the `targetElement` is some kind of special null value?
  
  An alternative seems to be this:
  
  ```
  {% set drinksWithNoIngredients = craft.entries.section("drinks") %}
  {% for drink in drinksWithNoIngredients %}
      {% if not drink.ingredients.total() %}
      <p>Do something with {{ drink.title }}...</p>
  
  ```
  
  But doing it that way calls `.total()` on *every* drink. Is that going to cause performance problems if I have a lot of drinks?
  
  **Tags:** elementcriteriamodel
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-04-16. Score: 2 | Accepted answer
  
  You were on the right track using `relatedTo`. But as there's no `notRelatedTo` parameter, you'd first have to get all drinks that are related to any ingredient and those entries can then be removed from a new ElementCriteriaModel, that returns all your drinks, using Craft's [`without`](http://buildwithcraft.com/docs/templating/filters#without) filter. Instead of passing whole element models, you should better use this filter with element IDs (→ [Why is the Craft without filter not working correctly and how to debug?](https://craftcms.stackexchange.com/q/7170/125)). To get them just make use of the [`ids()`](http://buildwithcraft.com/docs/templating/elementcriteriamodel#ids) method.
  
  ```
  {% set ingredients = craft.entries.section('ingredients').limit(null) %}
  {% set drinksWithIngredientsIds = craft.entries.section('drinks').relatedTo({targetElement: ingredients}).limit(null).ids() %}
  
  {% set drinksWithNoIngredients = craft.entries.section('drinks')|without(drinksWithIngredientsIds) %}
  
  ```
  
  > **Comments:**
  > **username_0**: Genius! Thanks so much. On a minor note, I had to change the last line to retrieve ids: `{% set drinksWithNoIngredientsIds = craft.entries.section('drinks').ids()|without(drinksWithIngredientsIds) %}` for the `without` filter to kick in. I then was able to get all the entries I wanted via: `craft.entries.id(drinksWithNoIngredientsIds)`.  
  > **username_0**: Also, out of curiosity, what role does the `.limit(null)` parameter play in the first two lines of code?  
  > **username_1**: `limit` is set to 100 by default. So it just makes sure you include all the ingredients, last line is for the output and you can limit or paginate to your liking.  
  
  ---
  
  