Answers.Body: <p>OK in fact it was very simple: criteria params accept arrays...  </p>
  
  <pre><code>        $criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
  
          $fields = [
              'articleBody.efficyDocuments',
              'efficyDocuments'
          ];
  
          $criteria-&gt;relatedTo = array(
              'targetElement' =&gt; $asset-&gt;id,
              'field' =&gt; $fields,
          );
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-15T00:19:56.357Z
Answers.LastActivityDate: 2015-08-15T00:19:56.357Z
Answers.UserDisplayName: migmaker
Body: <p>I got an asset field called <code>docs</code> which is contained in 2 different entries.<br>
  Those entries are in different sections and they contain the <code>docs</code> field <strong>directly</strong> or through a <strong>matrix</strong> field called <code>articleBody</code>.</p>
  
  <p>I made two queries relatedTo and merge them thereafter.<br>
  It works but would it be a better way by combining the two queries in one <strong>relatedTo</strong> call?</p>
  
  <p>Query 1: <code>pages</code> section entries contain <code>docs</code> field inside a matrix field called <code>articleBody</code><br>
  Query 2: <code>library</code> section entries contain <code>docs</code> field directly</p>
  
  <pre><code>        $criteria1 = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
          $criteria1-&gt;section = 'pages';
          $criteria1-&gt;relatedTo = array(
              'targetElement' =&gt; $asset-&gt;id,
              'field' =&gt; 'articleBody.docs'
          );
  
          $criteria2 = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
          $criteria2-&gt;section = 'library';
          $criteria2-&gt;relatedTo = array(
              'targetElement' =&gt; $asset-&gt;id,
              'field' =&gt; 'docs'
          );
  
          $criteria = array_merge($criteria1, $criteria2);
  </code></pre>
  
Tags: <relations><entries-field>
Title: Get different kind of entries relatedTo one asset (many to one)?
ThreadText: # Get different kind of entries relatedTo one asset (many to one)?
  
  (Asked by: username_0 on 2015-08-15)
  
  I got an asset field called `docs` which is contained in 2 different entries.  
  Those entries are in different sections and they contain the `docs` field **directly** or through a **matrix** field called `articleBody`.
  
  I made two queries relatedTo and merge them thereafter.  
  It works but would it be a better way by combining the two queries in one **relatedTo** call?
  
  Query 1: `pages` section entries contain `docs` field inside a matrix field called `articleBody`  
  Query 2: `library` section entries contain `docs` field directly
  
  ```
          $criteria1 = craft()->elements->getCriteria(ElementType::Entry);
          $criteria1->section = 'pages';
          $criteria1->relatedTo = array(
              'targetElement' => $asset->id,
              'field' => 'articleBody.docs'
          );
  
          $criteria2 = craft()->elements->getCriteria(ElementType::Entry);
          $criteria2->section = 'library';
          $criteria2->relatedTo = array(
              'targetElement' => $asset->id,
              'field' => 'docs'
          );
  
          $criteria = array_merge($criteria1, $criteria2);
  
  ```
  
  **Tags:** relations, entries-field
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2015-08-15. Score: 2 | Accepted answer
  
  OK in fact it was very simple: criteria params accept arrays...
  
  ```
          $criteria = craft()->elements->getCriteria(ElementType::Entry);
  
          $fields = [
              'articleBody.efficyDocuments',
              'efficyDocuments'
          ];
  
          $criteria->relatedTo = array(
              'targetElement' => $asset->id,
              'field' => $fields,
          );
  
  ```
  
  
  ---
  
  