Answers.Body: <p>It’s not currently possible to specify both of those conditions at once with the relatedTo param, so you would have to do it with two separate queries.</p>
  
  <p>First, get all of the asset IDs that are related to the upload entries:</p>
  
  <pre><code>{% set uploadAssetIds = craft.assets.relatedTo(uploads).ids() %}
  </code></pre>
  
  <p>(Note that the relatedToUploads variable is not actually necessary here.)</p>
  
  <p>Then you would get all of the assets whose ID falls within one of the uploadAssetIds, <strong>and</strong> who are related to all of the tag IDs.</p>
  
  <pre><code>{% set relatedToTags = ['and'] %}
  ...
  
  {% set assets = craft.assets.id(uploadAssetIds).relatedTo(relatedToTags) %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-05T01:25:44.263Z
Answers.LastActivityDate: 2014-11-05T01:25:44.263Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>In my template, I want to:</p>
  
  <ul>
  <li>Get all the entries in the section 'uploads';</li>
  <li>Get all the assets that are related to <strong>one of the</strong> upload entries, <strong>and</strong> have a relation to all the tags I provide.</li>
  </ul>
  
  <p>So, that would be:</p>
  
  <pre><code>{% set company = craft.entries.section('company').id(companyId).first() %}
  {% set uploads = craft.entries.section('uploads').relatedTo(company).limit(null) %}
  
  {% set relatedToUploads = ['or'] %}
  {% for upload in uploads %}
      {% set relatedToUploads = relatedToUploads | merge([upload.id]) %}
  {% endfor %}
  
  {% set relatedToTags = ['and'] %}
  {% for tag in tags %}
      {% set relatedToTags = relatedToTags | merge([tag.id]) %}
  {% endfor %}
  </code></pre>
  
  <p>But, how would I combine those two relatedTo-arrays to one, usable in the ElementCriteriaModel for the assets?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-11-04T23:49:37.060Z
Comments.Text: Where is carlsc and his ElementCriteriaModel foo when you need him?! You might check out [this post](http://craftcms.stackexchange.com/questions/1948/complex-logic-on-a-elementcriteriamodel-parameter) or [this post](http://craftcms.stackexchange.com/questions/4475/merge-two-arrays-of-elementmodels/4479#4479) for some hints on combining and/or and merging elements. It may help.
Comments.UserDisplayName: Douglas McDonald
Tags: <entries><assets><relations><elementcriteriamodel>
Title: How can I create an ElementCriteriaModel with 'and' and 'or'
ThreadText: # How can I create an ElementCriteriaModel with 'and' and 'or'
  
  (Asked by: username_0 on 2014-11-04)
  
  In my template, I want to:
  
  * Get all the entries in the section 'uploads';
  * Get all the assets that are related to **one of the** upload entries, **and** have a relation to all the tags I provide.
  
  So, that would be:
  
  ```
  {% set company = craft.entries.section('company').id(companyId).first() %}
  {% set uploads = craft.entries.section('uploads').relatedTo(company).limit(null) %}
  
  {% set relatedToUploads = ['or'] %}
  {% for upload in uploads %}
      {% set relatedToUploads = relatedToUploads | merge([upload.id]) %}
  {% endfor %}
  
  {% set relatedToTags = ['and'] %}
  {% for tag in tags %}
      {% set relatedToTags = relatedToTags | merge([tag.id]) %}
  {% endfor %}
  
  ```
  
  But, how would I combine those two relatedTo-arrays to one, usable in the ElementCriteriaModel for the assets?
  
  **Tags:** entries, assets, relations, elementcriteriamodel
  
  > **Comments:**
  > **username_1**: Where is carlsc and his ElementCriteriaModel foo when you need him?! You might check out [this post](http://craftcms.stackexchange.com/questions/1948/complex-logic-on-a-elementcriteriamodel-parameter) or [this post](http://craftcms.stackexchange.com/questions/4475/merge-two-arrays-of-elementmodels/4479#4479) for some hints on combining and/or and merging elements. It may help.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2014-11-05. Score: 4 | Accepted answer
  
  It’s not currently possible to specify both of those conditions at once with the relatedTo param, so you would have to do it with two separate queries.
  
  First, get all of the asset IDs that are related to the upload entries:
  
  ```
  {% set uploadAssetIds = craft.assets.relatedTo(uploads).ids() %}
  
  ```
  
  (Note that the relatedToUploads variable is not actually necessary here.)
  
  Then you would get all of the assets whose ID falls within one of the uploadAssetIds, **and** who are related to all of the tag IDs.
  
  ```
  {% set relatedToTags = ['and'] %}
  ...
  
  {% set assets = craft.assets.id(uploadAssetIds).relatedTo(relatedToTags) %}
  
  ```
  
  
  ---
  
  