Expression builder doesn't convert boolean value to 0 or 1. #4934

Closed
opened 2026-01-22 14:52:47 +01:00 by admin · 2 comments
Owner

Originally created by @tomazahlin on GitHub (Dec 11, 2015).

Originally assigned to: @Ocramius on GitHub.

I am using query builder and the expression builder to create a query.

$qb->andWhere($qb->expr()->eq('a.property', false));

Generates: "WHERE ... a.property = " (without any value)

While

$qb->andWhere($qb->expr()->eq('a.property', true));

Generates: "WHERE a.property = 1"

And

$qb->andWhere($qb->expr()->eq('a.property', 0));

Generates: "WHERE a.property = 0"

The property is annotated as boolean and doctrine knows it is boolean too. Any suggestions?

Thank you.

Originally created by @tomazahlin on GitHub (Dec 11, 2015). Originally assigned to: @Ocramius on GitHub. I am using query builder and the expression builder to create a query. ``` php $qb->andWhere($qb->expr()->eq('a.property', false)); ``` Generates: `"WHERE ... a.property = "` (without any value) While ``` php $qb->andWhere($qb->expr()->eq('a.property', true)); ``` Generates: `"WHERE a.property = 1"` And ``` php $qb->andWhere($qb->expr()->eq('a.property', 0)); ``` Generates: `"WHERE a.property = 0"` The property is annotated as boolean and doctrine knows it is boolean too. Any suggestions? Thank you.
admin added the BugInvalid labels 2026-01-22 14:52:47 +01:00
admin closed this issue 2026-01-22 14:52:47 +01:00
Author
Owner

@Ocramius commented on GitHub (Dec 11, 2015):

This is expected behavior: the query builder is a string builder, and it doesn't care about the types of the passed in parameters: it just converts them to strings in the end.

What you are supposed to do with any parameter is to use parameter binding instead:

$qb->andWhere($qb->expr()->eq('a.property', ':propertyCheck'));
$qb->setParameter('propertyCheck', false);
@Ocramius commented on GitHub (Dec 11, 2015): This is expected behavior: the query builder is a string builder, and it doesn't care about the types of the passed in parameters: it just converts them to strings in the end. What you are supposed to do with any parameter is to use parameter binding instead: ``` php $qb->andWhere($qb->expr()->eq('a.property', ':propertyCheck')); $qb->setParameter('propertyCheck', false); ```
Author
Owner

@tomazahlin commented on GitHub (Dec 14, 2015):

Thank you for the help, sounds fine.

@tomazahlin commented on GitHub (Dec 14, 2015): Thank you for the help, sounds fine.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#4934