Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Criteria is incorrectly serializing values on array field #7822

Open
hubertnnn opened this issue Sep 18, 2019 · 1 comment
Open

Criteria is incorrectly serializing values on array field #7822

hubertnnn opened this issue Sep 18, 2019 · 1 comment

Comments

@hubertnnn
Copy link

Bug Report

Q A
BC Break no
Version 2.6.3

Summary

When trying to use Criteria on array type of field, the value is incorrectly serialized.

Field definition:

    /**
     * @ORM\Column(name="roles", type="array")
     */
    private $roles = [];

Criteria usage:

        $criteria = new Criteria();
        $criteria->where($criteria->expr()->contains('roles', 'ROLE_ADMIN'));

        $em = $this->container->get('doctrine')->getManager();
        $data = $em->getRepository(User::class)->matching($criteria);
        foreach ($data as $row) {
            $row->getRoles(); // Force LAZY_LOAD
        }

Current behavior

Generated SQL contains following where clause:
WHERE t0.roles LIKE 's:12:\"%ROLE_ADMIN%\";'

Expected behavior

Where statement should not be serialized:
WHERE t0.roles LIKE '%ROLE_ADMIN%'
or should be serialized before adding percent signs:
WHERE t0.roles LIKE '%s:10:\"ROLE_ADMIN\";%'

@Ocramius
Copy link
Member

Ocramius commented Sep 18, 2019

Hmm, seems correct behavior, since the conversion goes through SQL conversions in the DBAL type.

The problem is that it certainly isn't obvious to the consumer, but do imagine doing the same with a DateTime instance: a conversion would most certainly be expected.

EDIT: sorry, didn't mean to close

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants