Answers.Body: <p>After doing a bit more digging, I think the only real option here is run a preliminary query to pull out the ids of the elements I want and then pass that into the ElementCriteriaModel. It's not ideal, but it'll do.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-10T15:21:00.940Z
Answers.LastActivityDate: 2017-01-10T15:21:00.940Z
Answers.UserDisplayName: Michael Witwicki
Body: <p>Working with the <a href="https://github.com/pixelandtonic/ElementAPI" rel="nofollow noreferrer">Element API</a> for the first time and I'm having a bit of a hard time finding any kind of documentation regarding writing more complex conditionals using the <a href="https://craftcms.com/docs/templating/elementcriteriamodel" rel="nofollow noreferrer">ElementCriteriaModel</a>.</p>
  
  <p>What I'm trying to accomplish, is selecting all entries (they are events with a start/end date as custom fields) from a given section, which overlap in any way with a passed-in query start/end date.</p>
  
  <p>It is probably easier to simply supply the raw query that works, and perhaps someone could point me in the direction of documentation that could help me.</p>
  
  <pre><code>SELECT *
  FROM craft_content
  WHERE
  ! ( field_eventStartDate &gt; @queryStartDate AND field_eventStartDate &gt; @queryEndDate)
  AND
  ! ( field_eventEndDate &lt; @queryStartDate AND field_eventEndDate &lt; @queryEndDate )
  </code></pre>
  
Tags: <elementcriteriamodel><plugin-elementapi>
Title: Complex Conditionals with ElementCriteriaModel / Element API
ThreadText: # Complex Conditionals with ElementCriteriaModel / Element API
  
  (Asked by: username_0 on 2017-01-09)
  
  Working with the [Element API](https://github.com/pixelandtonic/ElementAPI) for the first time and I'm having a bit of a hard time finding any kind of documentation regarding writing more complex conditionals using the [ElementCriteriaModel](https://craftcms.com/docs/templating/elementcriteriamodel).
  
  What I'm trying to accomplish, is selecting all entries (they are events with a start/end date as custom fields) from a given section, which overlap in any way with a passed-in query start/end date.
  
  It is probably easier to simply supply the raw query that works, and perhaps someone could point me in the direction of documentation that could help me.
  
  ```
  SELECT *
  FROM craft_content
  WHERE
  ! ( field_eventStartDate > @queryStartDate AND field_eventStartDate > @queryEndDate)
  AND
  ! ( field_eventEndDate < @queryStartDate AND field_eventEndDate < @queryEndDate )
  
  ```
  
  **Tags:** elementcriteriamodel, plugin-elementapi
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2017-01-10. Score: 3 | Accepted answer
  
  After doing a bit more digging, I think the only real option here is run a preliminary query to pull out the ids of the elements I want and then pass that into the ElementCriteriaModel. It's not ideal, but it'll do.
  
  
  ---
  
  