Open grzegorz-stolarz opened 4 years ago
@grzegorz-stolarz I'm afraid I don't understand the proposed fix. Could you please post a diff
of the code needed to support this? Generally speaking we don't support custom Doctrine types ... but if the needed changes are minimal, we could do something.
Index: src/Orm/EntityRepository.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/Orm/EntityRepository.php (revision c7e880ea107ee7f083b2ddeeaf9bae6fd4f1b5dc)
+++ src/Orm/EntityRepository.php (date 1604482012748)
@@ -2,6 +2,10 @@
namespace EasyCorp\Bundle\EasyAdminBundle\Orm;
+use Doctrine\DBAL\Platforms\PostgreSQL100Platform;
+use Doctrine\DBAL\Platforms\PostgreSQL91Platform;
+use Doctrine\DBAL\Platforms\PostgreSQL92Platform;
+use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
use Doctrine\ORM\QueryBuilder;
use Doctrine\Persistence\ManagerRegistry;
use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection;
@@ -25,6 +29,16 @@
private $entityFactory;
private $formFactory;
+ /**
+ * @var string[] PostgreSQL Platforms
+ */
+ private static $postgreSQLPlatforms = [
+ PostgreSQL91Platform::class,
+ PostgreSQL92Platform::class,
+ PostgreSQL94Platform::class,
+ PostgreSQL100Platform::class,
+ ];
+
public function __construct(AdminContextProvider $adminContextProvider, ManagerRegistry $doctrine, EntityFactory $entityFactory, FormFactory $formFactory)
{
$this->adminContextProvider = $adminContextProvider;
@@ -64,6 +78,7 @@
$isSmallIntegerQuery = ctype_digit($query) && $query >= -32768 && $query <= 32767;
$isIntegerQuery = ctype_digit($query) && $query >= -2147483648 && $query <= 2147483647;
$isUuidQuery = 1 === preg_match('/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i', $query);
+ $databasePlatform = get_class($this->doctrine->getConnection()->getDatabasePlatform());
$dqlParameters = [
// adding '0' turns the string into a numeric value
@@ -134,6 +149,9 @@
->setParameter('query_for_text', $dqlParameters['text_query']);
$queryBuilder->orWhere(sprintf('LOWER(%s.%s) IN (:query_as_words)', $entityName, $propertyName))
->setParameter('query_as_words', $dqlParameters['words_query']);
+ } else if (!in_array($databasePlatform, self::$postgreSQLPlatforms)) {
+ $queryBuilder->orWhere(sprintf('LOWER(%s.%s) LIKE :query_for_text', $entityName, $propertyName))
+ ->setParameter('query_for_text', $dqlParameters['text_query']);
}
}
}
@@ -195,4 +213,4 @@
++$i;
}
}
-}
+}
\ No newline at end of file
It's a patch ;-) I've only added checks for PostgreSQL platforms (even removed or flagged as deprecated). It will search as text.
@grzegorz-stolarz I know this is an old issue. But would you be up for a PR?
Describe the bug In version 3.1.6 was added support for search on 2 level nested fields. It's fine, I've tested it and it works, but author completely forgot about enums fields which could be added and their type is non-string so search didn't work.
To Reproduce Use custom enum field with ORM
(OPTIONAL) Additional context In
EntityRepository.php
within methodaddSearchClause
we can fix it within this code.I know, it's deprecated class but we can create a map for PostgreSQL classes which will be avoided to use this search. Hope I could help 👍