title: Doctrine: No custom field type appliement in CASE WHEN
body: <p>I'm trying to apply a custom property type within a CASE WHEN condition.</p>
  
  <p>My custom Type:</p>
  
  <pre><code>&lt;?php
  
  [NAMESPACE GOES HERE]
  
  [USE STATEMENTS GO HERE]
  
  class AesType extends Type
  {
      const AES = 'aes';
  
      public function getName()
      {
          return self::AES;
      }
  
      public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
      {
          return 'TEXT';
      }
  
      public function convertToPHPValue($value, AbstractPlatform $platform)
      {
      [OPERATIONS TO MODIFY $value. THIS WORKS WELL IN MOST CASES]
  
          return $value;
      }
  
      public function convertToDatabaseValue($value, AbstractPlatform $platform)
      {
      [OPERATIONS TO MODIFY $value. THIS WORKS WELL IN MOST CASES]
  
          return $value;
      }
  }
  </code></pre>
  
  <p>If i do fetches in a simple select everything works fine. But if i "fetch" or "apply" values in a CASE WHEN it seems that my type modifications are not applied.</p>
  
  <p>Bellow is a code snippet of the relevant part.</p>
  
  <pre><code>$fieldsStatic = [];
  
  while($dateTimeLoop &lt;= $dateTimeForeCast) {
    $date = $dateTimeLoop-&gt;format('Y-m-d');
    $selection = 'CASE WHEN (((DATE(salaryContract.dateFrom) &lt;= \'' . $date . '\') AND (salaryContract.dateUntil IS NULL)) OR ((salaryContract.dateUntil IS NOT NULL) AND (DATE(salaryContract.dateUntil) &gt;= \'' . $date . '\') AND (DATE(salaryContract.dateFrom) &lt;= \'' . $date . '\'))) THEN salary.amount ELSE \'-\' END';
    $as = 'AS salary_' . $dateTimeLoop-&gt;format('Y') . '_' . $dateTimeLoop-&gt;format('m');
    $fieldsDynamic[] = $selection . ' ' . $as;
  
    $dateTimeLoop-&gt;add(new \DateInterval('P' . Salary::CSV_EXPORT_INTERVAL_MONTHS . 'M'));
  }
  
  $fields = array_merge($fieldsStatic, $fieldsDynamic);
  
  $query = self::getEntityManager()-&gt;createQueryBuilder()-&gt;select($fields)-&gt;from(self::getModel(), 'salary');
  
  $result = $query-&gt;getQuery()-&gt;getArrayResult();
  </code></pre>
  
  <p>If i know dump $result the value of salary.amount ist still AES encrypted but the type of amount is declared as "aes" like so: (This is still only the relevant part of the model)</p>
  
  <pre><code>/**
   * @ORM\Entity
   *
   * @ORM\Table(
   *     name="emd_salary",
   * )
   *
   * @ORM\HasLifeCycleCallbacks
   */
  class Salary
  {
      const CSV_EXPORT_INTERVAL_MONTHS = 1;
  
      /**
       * @var string
       *
       * @ORM\Column(name="amount", type="aes", nullable=true)
       */
      protected $amount;
  }
  </code></pre>
  
  <p>I have added the type correctly to my setup routine like so:</p>
  
  <pre><code>Type::addType('aes', AesType::class);
  
  $entityManager-&gt;getConnection()-&gt;getDatabasePlatform()-&gt;registerDoctrineTypeMapping('aes', 'aes');
  </code></pre>