in with type boolean fails #5915

Closed
opened 2026-01-22 15:22:00 +01:00 by admin · 4 comments
Owner

Originally created by @michsk on GitHub (Mar 12, 2018).

When using in for a where query with a property that has a type of boolean, the query fails. The results returned are always the rows whiche have a value of 0, false. Mysql.

When i change it to eq, and pass a 1 or true as value. Than the results are correct.

    /**
     * @var bool
     * @ORM\Column(type="boolean", name="archive")
     */
    private $archive;
$cr->where(Criteria::expr()->in('archive', [1])); //returns invalid resut
$cr->where(Criteria::expr()->eq('archive', 1)); //returns correct result
Originally created by @michsk on GitHub (Mar 12, 2018). When using `in` for a `where` query with a property that has a type of `boolean`, the query fails. The results returned are always the rows whiche have a value of `0`, `false`. Mysql. When i change it to `eq`, and pass a 1 or true as value. Than the results are correct. ```php /** * @var bool * @ORM\Column(type="boolean", name="archive") */ private $archive; ``` ```php $cr->where(Criteria::expr()->in('archive', [1])); //returns invalid resut ``` ```php $cr->where(Criteria::expr()->eq('archive', 1)); //returns correct result ```
admin closed this issue 2026-01-22 15:22:00 +01:00
Author
Owner

@Ocramius commented on GitHub (Mar 12, 2018):

$cr->where(Criteria::expr()->in('archive', [1])); //returns invalid resut

What is "invalid result"?

Can this be verified in isolation? See 43c252458b/tests/Doctrine/Tests/ORM/Functional/Ticket for examples

@Ocramius commented on GitHub (Mar 12, 2018): > `$cr->where(Criteria::expr()->in('archive', [1])); //returns invalid resut` What is "invalid result"? Can this be verified in isolation? See https://github.com/doctrine/doctrine2/tree/43c252458b1c46081b828555013bb3fb0bb3c389/tests/Doctrine/Tests/ORM/Functional/Ticket for examples
Author
Owner

@michsk commented on GitHub (Mar 12, 2018):

"Invalid result", as in it returns the results where the archive value (in the database) is 0 (false). When what we ask for is 1 (true).

I'll look at the link given and come back asap.

@michsk commented on GitHub (Mar 12, 2018): "Invalid result", as in it returns the results where the archive value (in the database) is 0 (false). When what we ask for is 1 (true). I'll look at the link given and come back asap.
Author
Owner

@michsk commented on GitHub (Mar 12, 2018):

I read all the readmes and xml files but i cant get it to use my local database.

So the test now fails with a invalid parameter type: 105

<?php
declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Annotation as ORM;
use Doctrine\Tests\OrmFunctionalTestCase;

final class GH7126Test extends OrmFunctionalTestCase
{
    protected function setUp() : void
    {
        parent::setUp();
        $this->setUpEntitySchema([GH7126UserData::class]);
        $this->createInitialEntries();
    }

    private function createInitialEntries(): void
    {
        $this->em->persist(new GH7126UserData(true));
        $this->em->persist(new GH7126UserData(false));

        $this->em->flush();
        $this->em->clear();
    }

    /**
     * @group gh7126
     */
    public function testReturnsResultWithTrueWhenMatchingForFalse() : void
    {
        $cr = Criteria::create();
        $cr->andWhere(Criteria::expr()->in('archive', [1]));

        $result = $this->em->getRepository(GH7126UserData::class);
        $data = $result->matching($cr);

        self::assertFalse($data[0]->archive);
    }
}


/**
 * @ORM\Entity
 * @ORM\Table(name="in-with-boolean")
 */
class GH7126UserData
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     */
    public $id;

    /** @ORM\Column(type="boolean", name="archive") */
    public $archive;

    public function __construct(bool $archive = false)
    {
        $this->archive = $archive;
    }
}
@michsk commented on GitHub (Mar 12, 2018): I read all the readmes and xml files but i cant get it to use my local database. So the test now fails with a `invalid parameter type: 105` ```php <?php declare(strict_types=1); namespace Doctrine\Tests\ORM\Functional\Ticket; use Doctrine\Common\Collections\Criteria; use Doctrine\ORM\Annotation as ORM; use Doctrine\Tests\OrmFunctionalTestCase; final class GH7126Test extends OrmFunctionalTestCase { protected function setUp() : void { parent::setUp(); $this->setUpEntitySchema([GH7126UserData::class]); $this->createInitialEntries(); } private function createInitialEntries(): void { $this->em->persist(new GH7126UserData(true)); $this->em->persist(new GH7126UserData(false)); $this->em->flush(); $this->em->clear(); } /** * @group gh7126 */ public function testReturnsResultWithTrueWhenMatchingForFalse() : void { $cr = Criteria::create(); $cr->andWhere(Criteria::expr()->in('archive', [1])); $result = $this->em->getRepository(GH7126UserData::class); $data = $result->matching($cr); self::assertFalse($data[0]->archive); } } /** * @ORM\Entity * @ORM\Table(name="in-with-boolean") */ class GH7126UserData { /** * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") */ public $id; /** @ORM\Column(type="boolean", name="archive") */ public $archive; public function __construct(bool $archive = false) { $this->archive = $archive; } } ```
Author
Owner

@beberlei commented on GitHub (Dec 7, 2020):

I think the problem is that you have to do $cr->andWhere(Criteria::expr()->in('archive', [true]));

@beberlei commented on GitHub (Dec 7, 2020): I think the problem is that you have to do `$cr->andWhere(Criteria::expr()->in('archive', [true]));`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5915