title: What is the most efficient way to conduct a search into a OneToMany relationship using doctrine on Symfony 4?
body: <p>I have two entities (User and Product) with a OneToMany relationship. I want to retrieve all Product entities related to a specific User filtering them by a field called "finished". I will post the relevant information of those entities:</p>
  
  <p>User Entity:</p>
  
  <pre><code>/**
   * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
   */
  class User implements UserInterface
  {
      /**
       * @ORM\Id()
       * @ORM\GeneratedValue()
       * @ORM\Column(type="integer")
       */
      private $id;
  
      /**
       * @ORM\OneToMany(targetEntity="App\Entity\Product", mappedBy="user")
       */
      private $products;
  
  
      ....
  </code></pre>
  
  <p>Product Entity:</p>
  
  <pre><code>/**
   * @ORM\Entity(repositoryClass="App\Repository\Productepository")
   */
  class Product
  {
      /**
       * @ORM\Id()
       * @ORM\GeneratedValue()
       * @ORM\Column(type="integer")
       */
      private $id;
  
      /**
       * @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="products")
       * @ORM\JoinColumn(nullable=false)
       */
      private $user;
  
      /**
       * @ORM\Column(type="boolean")
       */
      private $finished;
  
  
      ....
  </code></pre>
  
  <p>I am using the following code to filter my products, but is there any other more efficient way to do it?</p>
  
  <pre><code>$user = $this-&gt;getUser();
  $products = $user-&gt;getProducts();
  $filtered = [];
  
  foreach ($products as $product){
      if(!$product-&gt;getFinished()){
          $filtered[] = $product;
      }
  }
  </code></pre>
  
  <p>Thanks for your help</p>