8000 Paginator won't take into account entity identifiers that use custom DBAL types · Issue #7820 · doctrine/orm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Paginator won't take into account entity identifiers that use custom DBAL types #7820
Closed
@Ocramius

Description

@Ocramius

Bug Report

Q A
BC Break no
Version 2.6.3

Summary

When using a Doctrine\ORM\Tools\Pagination\Paginator to iterate over a query that has entities with a custom DBAL type used in the identifier, then $id->__toString() is used implicitly by PDO, instead of being converted by the Doctrine\DBAL\Types system.

In order to reproduce this, you must have identifiers implementing #__toString() (to allow the UnitOfWork to hash them) and other accessors that are used by the custom DBAL type during DB/PHP conversions. If #__toString() and the DBAL type conversions are asymmetric, then the paginator will fail to find records.

Tricky situation, but this very much affects ramsey/uuid-doctrine and anyone relying on the uuid_binary.

Current behavior

class MyEntity {
    public TheId $id;
}

class TheId {
    public function toId() : string
    {
        return 'yep';
    }
    public function __toString() : string
    {
        return 'nope';
    }
}

class TheIdType extends StringType
{
    public function convertToDatabaseValue($value, $platform)
    {
        return $value->toId();
    }
}

$entity = new MyEntity();
$entity->id = new TheId();

$em->persist($entity);
$em->flush();

$paginator = (new Paginator($em->createQuery('SELECT f FROM ' . MyEntity::class . ' f'));

foreach ($paginator as $entry) {
    die('this won't be reached with current ORM state');
}

Expected behavior

The code above should loop over one found record.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0