title: How to compare id in array Twig
body: <p>In my project I have to display a list of <code>DOSSIERS</code> that have the same department as the logged user — who can have 1 to N departments. A <code>DOSSIER</code> has only one department.</p>
  <p>So I would like to make a condition that would display that <code>DOSSIERS</code> that have a <code>department.id</code> present in the user's array of department.</p>
  <p>Here is my code, which display nothing:</p>
  <pre><code>{% for user in user.departement  %}
      {% for dossier in dossier %}
      {# &lt;p&gt; DOSSIER TEST: {{ dossier.id }} &lt;/p&gt; #}
          {% if user.id == dossier.id %}
            &lt;p&gt; DOSSIER ID: {{ dossier.id }} &lt;tr&gt;
        &lt;th scope=&quot;row&quot;&gt; {{ dossier.id }} &lt;/th&gt;
        &lt;td&gt;{{ dossier.id }}&lt;/td&gt;
        &lt;td&gt;{{ dossier.CP}}&lt;/td&gt;
        &lt;td&gt; {{ dossier.statut.nom}} &lt;/td&gt;
        &lt;td&gt; {{ dossier.departement.id}} &lt;/td&gt; &lt;/p&gt;
          {% endif %}
      {% endfor %}
  {% endfor %} 
  
  </code></pre>
  <p>EDIT</p>
  <p>I did use the code you gave me but I don’t have anything showing, even the &quot;DOSSIER ID:&quot;. Here the page returned:  <a href="https://i.stack.imgur.com/4sHNK.png" rel="nofollow noreferrer">https://i.stack.imgur.com/4sHNK.png</a></p>
  <pre><code>{% for dossier in dossier %}
          {% if dossier.departement.id in user.departement | column('id') %}
              &lt;tr&gt;
                  &lt;th scope=&quot;row&quot;&gt;DOSSIER ID: {{ dossier.id }}&lt;/th&gt;
                  &lt;td&gt;{{ dossier.CP }}&lt;/td&gt;
                  &lt;td&gt;{{ dossier.statut.nom }}&lt;/td&gt;
                  &lt;td&gt;{{ dossier.departement.id }}&lt;/td&gt;
              &lt;/tr&gt;
          {% endif %}
  
  </code></pre>
  <p>Here are my entities properties for more details:</p>
  <pre><code>/**
   * @ORM\Entity(repositoryClass=DossierRepository::class)
   */
  class Dossier
  {
      /**
       * @ORM\Id
       * @ORM\GeneratedValue
       * @ORM\Column(type=&quot;integer&quot;)
       */
      private $id;
  
  
      /**
       * @ORM\Column(type=&quot;string&quot;, length=255)
       */
      private $nom;
  
      /**
       * @ORM\Column(type=&quot;string&quot;, length=255)
       */
      private $prenom;
  
      /**
       * @ORM\Column(type=&quot;string&quot;, length=255)
       */
      private $adresse;
  
  
      /**
       * @ORM\Column(type=&quot;string&quot;, length=255)
       */
      private $ville;
  
      /**
       * @ORM\Column(type=&quot;string&quot;, length=255)
       */
      private $proploc;
  
      /**
       * @ORM\Column(type=&quot;string&quot;, length=255)
       */
      private $CodeSecurite;
  
      /**
       * @ORM\Column(type=&quot;string&quot;, length=255)
       */
      private $Cp;
  
  
      /**
       * @ORM\Column(type=&quot;float&quot;)
       */
      private $NumPortable;
  
     
  
      /**
       * @ORM\Column(type=&quot;datetime&quot;)
       */
      private $DateCreation;
  
      
      /**
       * @ORM\ManyToOne(targetEntity=Travaux::class, inversedBy=&quot;dossiers&quot;)
       * @ORM\JoinColumn(nullable=false)
       */
      private $travaux;
  
      /**
       * @ORM\ManyToMany(targetEntity=User::class, inversedBy=&quot;dossiers&quot;)
       */
      private $user;
  
  
      /**
       * @ORM\OneToOne(targetEntity=Document::class, mappedBy=&quot;Dossier&quot;, cascade={&quot;persist&quot;, &quot;remove&quot;})
       */
      private $document;
  
      /**
       * @ORM\ManyToMany(targetEntity=Impots::class, inversedBy=&quot;dossiers&quot;)
       */
      private $impot;
  
      /**
       * @ORM\Column(type=&quot;string&quot;, length=255, nullable=true)
       */
      private $Electricite;
  
      /**
       * @ORM\Column(type=&quot;string&quot;, length=255, nullable=true)
       */
      private $Combustible;
  
     
      /**
       * @ORM\ManyToOne(targetEntity=Statut::class, inversedBy=&quot;Dossier&quot;)
       * @ORM\JoinColumn(nullable=false)
       */
      private $statut;
  
      /**
       * @ORM\Column(type=&quot;smallint&quot;, nullable=true)
       */
      private $Etat;
  
  
      /**
       * @ORM\OneToMany(targetEntity=Message::class, mappedBy=&quot;DossierId&quot;)
       */
      private $messages;
  
      /**
       * @ORM\ManyToOne(targetEntity=Departements::class, inversedBy=&quot;dossiers&quot;)
       */
      private $departement;
  
      /**
       * @ORM\ManyToMany(targetEntity=Refuser::class, mappedBy=&quot;Dossier&quot;)
       */
      private $refusers;
  
  </code></pre>
  <pre><code>class Departements
  {
      /**
       * @ORM\Id
       * @ORM\GeneratedValue
       * @ORM\Column(type=&quot;integer&quot;)
       */
      private $id;
  
      /**
       * @ORM\Column(type=&quot;string&quot;, length=3)
       */
      private $RegionCode;
  
      /**
       * @ORM\Column(type=&quot;string&quot;, length=3)
       */
      private $code;
  
      /**
       * @ORM\Column(type=&quot;string&quot;, length=255)
       */
      private $name;
  
      /**
       * @ORM\Column(type=&quot;string&quot;, length=255)
       */
      private $slug;
  
      /**
       * @ORM\ManyToMany(targetEntity=User::class, mappedBy=&quot;departement&quot;)
       */
      private $users;
  
      /**
       * @ORM\OneToMany(targetEntity=Dossier::class, mappedBy=&quot;departement&quot;)
       */
      private $dossiers;
  </code></pre>
  <pre><code>class User implements UserInterface
  {
      /**
       * @ORM\Id
       * @ORM\GeneratedValue
       * @ORM\Column(type=&quot;integer&quot;)
       */
      private $id;
  
      /**
       * @ORM\Column(type=&quot;string&quot;, length=180, unique=true)
       * @Assert\Email(message=&quot;Veuillez renseigner un email valide !&quot;)
       */
      private $email;
  
      /**
       * @ORM\Column(type=&quot;json_array&quot;)
       */
      private $roles = [];
  
      /**
       * @var string The hashed password
       * @ORM\Column(type=&quot;string&quot;)
       */
      private $password;
  
      /**
       * @ORM\Column(type=&quot;string&quot;, length=255)
       */
      private $Entreprise;
  
      /**
       * @ORM\Column(type=&quot;string&quot;, length=255)
       */
      private $Adresse;
  
      /**
       * @ORM\Column(type=&quot;string&quot;, length=255)
       */
      private $Ville;
  
      /**
       * @ORM\Column(type=&quot;string&quot;, length=255)
       */
      private $Cp;
  
      /**
       * @ORM\ManyToMany(targetEntity=Dossier::class, mappedBy=&quot;user&quot;)
       */
      private $dossiers;
  
      /**
       * @ORM\OneToMany(targetEntity=Message::class, mappedBy=&quot;UserId&quot;)
       */
      private $messages;
  
      /**
       * @ORM\ManyToMany(targetEntity=Conversation::class, mappedBy=&quot;User&quot;)
       */
      private $conversations;
      /**
       * @ORM\ManyToMany(targetEntity=Departements::class, inversedBy=&quot;users&quot;)
       */
      private $departement;
  
  </code></pre>
  <p>Thank you !</p>