title: Filtering one-to-many connections in entity
body: <p>I have an entity User which has a one-to-many connection to questions. Questions has a one to many connection to answers. The question and answer entity each has a property called state.</p>
  
  <p>In generally after execute a GET request API Platform returns all users, with all questions including all answers. That works fine!</p>
  
  <p>Now I would like to implement a get request that returns the user with all questions that has a specific state (e.g. "X"). The questions should only include the answers with the same state ("X").</p>
  
  <p>I used the filter function (to filter the whole not necessary data)</p>
  
  <p>Therefore I generated a controller called GetUserObjectAction which the following function</p>
  
  <pre class="lang-php prettyprint-override"><code>  public function __invoke(PaginatorInterface $data, Request $request): PaginatorInterface
      {
  
          $repo = $this-&gt;managerRegistry-&gt;getRepository(Question::class);
  
  
         foreach ($data as $value) {
              $q = $value-&gt;getQuestions()-&gt;filter(function($q1) {
                      if($q1-&gt;getState() === 'a') {
                          $q1-&gt;values = $q1-&gt;values-&gt;filter(function($a) {
                              return $a-&gt;getState() === 'a';
                          });
  
                          return true;
                      } else {
                          return false;
                      }
                      return ;
                  });
  
              $value-&gt;setQuestions($int);
          }
          return $data;
      }
  </code></pre>
  
  <p>Is there a better way to implement it?</p>
  
  <p>Thanks</p>