Answers.Body: <p>That seems to be a bug / limitation of the <code>:notempty:</code> statement, it's probably adding its own ID criteria in the background and the merge doesn't work as expected. I'd suggest you file a bug report.</p>
  
  <p>In the meantime you could just add the "not empty asset field" criteria making use of the <code>relatedTo</code> parameter as a workaround. See <a href="https://craftcms.stackexchange.com/questions/129/how-can-i-get-only-those-entries-with-non-empty-assets-field">How can I get only those entries with non-empty assets field</a> for example code.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-31T21:25:44.063Z
Answers.Text: Excellent Carl, thanks. I guess I have to bite the bullet and use `relatedTo` on this one :)
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-31T21:23:33.860Z
Answers.LastActivityDate: 2016-03-31T21:23:33.860Z
Answers.LastEditDate: 2017-04-13T12:50:59.930Z
Answers.UserDisplayName: carlcs
Body: <p>I'm trying to pull a set of 3 random entries from a Section. The entries need to have a certain Assets field not empty, and I also have to exclude entries already pulled (these entries are stored in the variable <code>entriesA</code>).</p>
  
  <p>The issue is that with my current query, the ID exclusion doesn't work – i.e. I'm getting back entries found in <code>entriesA</code>.</p>
  
  <p>Here's how the query looks:</p>
  
  <pre><code>{% set entriesB = craft.entries({
      section : 'someSection',
      assetsField : ':notempty:',
      limit : 3,
      order : 'RAND()',
      id : 'and, not ' ~ entriesA.ids()|join(', not ')
  }) %}
  </code></pre>
  
  <p>The problem appears to be the <code>assetsField : ':notempty:'</code> statement – when I remove that, I get no duplicates. When it's included, Craft appears to ignore the <code>id</code> parameter and I get back duplicates.</p>
  
  <p>Anyone know what's up? Is it not possible to query using <code>:notempty:</code> statements <em>and</em> <code>id</code>?</p>
  
Tags: <templating><entries><relations>
Title: Get random entries, excluding an array of entry IDs, where a relational field is not empty
ThreadText: # Get random entries, excluding an array of entry IDs, where a relational field is not empty
  
  (Asked by: username_0 on 2016-03-31)
  
  I'm trying to pull a set of 3 random entries from a Section. The entries need to have a certain Assets field not empty, and I also have to exclude entries already pulled (these entries are stored in the variable `entriesA`).
  
  The issue is that with my current query, the ID exclusion doesn't work – i.e. I'm getting back entries found in `entriesA`.
  
  Here's how the query looks:
  
  ```
  {% set entriesB = craft.entries({
      section : 'someSection',
      assetsField : ':notempty:',
      limit : 3,
      order : 'RAND()',
      id : 'and, not ' ~ entriesA.ids()|join(', not ')
  }) %}
  
  ```
  
  The problem appears to be the `assetsField : ':notempty:'` statement – when I remove that, I get no duplicates. When it's included, Craft appears to ignore the `id` parameter and I get back duplicates.
  
  Anyone know what's up? Is it not possible to query using `:notempty:` statements *and* `id`?
  
  **Tags:** templating, entries, relations
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-03-31. Score: 4 | Accepted answer
  
  That seems to be a bug / limitation of the `:notempty:` statement, it's probably adding its own ID criteria in the background and the merge doesn't work as expected. I'd suggest you file a bug report.
  
  In the meantime you could just add the "not empty asset field" criteria making use of the `relatedTo` parameter as a workaround. See [How can I get only those entries with non-empty assets field](https://craftcms.stackexchange.com/questions/129/how-can-i-get-only-those-entries-with-non-empty-assets-field) for example code.
  
  > **Comments:**
  > **username_0**: Excellent Carl, thanks. I guess I have to bite the bullet and use `relatedTo` on this one :)  
  
  ---
  
  