Answers.Body: <p>Splitting the criteria up like this works.</p>
  
  <pre><code>$criteria-&gt;relatedTo = [
      'targetElement' =&gt; anElementId,
      'field'         =&gt; 'relationshipOne'
  ];
  $criteria-&gt;relationshipTwo = ':empty:';
  </code></pre>
  
  <p>Thanks to @carlcs in the Craft Slack channel.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-01T20:33:19.477Z
Answers.LastActivityDate: 2017-09-01T20:33:19.477Z
Answers.UserDisplayName: Benjamin Kohl
Body: <p>I have two relationship fields. I am trying to query all entries where the first field is related to a particular element and the second field is related to nothing. Here is how I <em>thought</em> it would work but it doesn't.</p>
  
  <pre><code>$criteria-&gt;relatedTo = ['and',
  [
      'targetElement' =&gt; anElementId,
      'field'         =&gt; 'relationshipOne'
  ],
  [
      'targetElement' =&gt; null, // also tried ":empty:"
      'field'         =&gt; 'relationshipTwo'
  ]];
  </code></pre>
  
Tags: <plugin-development><relations><elementcriteriamodel>
Title: How do I query two relationship fields where one relationship MUST be empty?
ThreadText: # How do I query two relationship fields where one relationship MUST be empty?
  
  (Asked by: username_0 on 2017-09-01)
  
  I have two relationship fields. I am trying to query all entries where the first field is related to a particular element and the second field is related to nothing. Here is how I *thought* it would work but it doesn't.
  
  ```
  $criteria->relatedTo = ['and',
  [
      'targetElement' => anElementId,
      'field'         => 'relationshipOne'
  ],
  [
      'targetElement' => null, // also tried ":empty:"
      'field'         => 'relationshipTwo'
  ]];
  
  ```
  
  **Tags:** plugin-development, relations, elementcriteriamodel
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2017-09-01. Score: 4 | Accepted answer
  
  Splitting the criteria up like this works.
  
  ```
  $criteria->relatedTo = [
      'targetElement' => anElementId,
      'field'         => 'relationshipOne'
  ];
  $criteria->relationshipTwo = ':empty:';
  
  ```
  
  Thanks to @carlcs in the Craft Slack channel.
  
  
  ---
  
  