ExpressionBuilder contains doesn't work for type INT #6296

Closed
opened 2026-01-22 15:30:20 +01:00 by admin · 2 comments
Owner

Originally created by @Stijn98s on GitHub (Sep 12, 2019).

Originally assigned to: @lcobucci on GitHub.

Bug Report

I want to filter entities with a Criteria. When using the contains from the ExpressionBuilder on VARCHAR fields it works correctly. When using this on INT fields i get nothing.

Q A
BC Break no
Version 2.6.3

When using the contains on VARCHAR i get correct entities back.

Current behavior

If i use contains('name', 'test') from a table like

Name Age
testie 11
testa 12
jhon 12

I correctly get

Name Age
testie 11
testa 12

But when i use contains('age', 1) I get

Name Age

How to reproduce

$criteria = Criteria::create()->where(Criteria::expr()->contains('age', 1));
$em->getRepository(User::class)->matching($criteria)

Expected behavior

I expect i get the following

Name Age
testie 11
testa 12
jhon 12
Originally created by @Stijn98s on GitHub (Sep 12, 2019). Originally assigned to: @lcobucci on GitHub. ### Bug Report I want to filter entities with a Criteria. When using the contains from the ExpressionBuilder on VARCHAR fields it works correctly. When using this on INT fields i get nothing. | Q | A |------------ | ------ | BC Break | no | Version | 2.6.3 When using the contains on VARCHAR i get correct entities back. #### Current behavior If i use `contains('name', 'test')` from a table like | Name | Age |------------ | ------ | testie | 11 | testa | 12 | jhon | 12 I correctly get | Name | Age |------------ | ------ | testie | 11 | testa | 12 But when i use `contains('age', 1)` I get | Name | Age |------------ | ------ #### How to reproduce ``` $criteria = Criteria::create()->where(Criteria::expr()->contains('age', 1)); $em->getRepository(User::class)->matching($criteria) ``` #### Expected behavior I expect i get the following | Name | Age |------------ | ------ | testie | 11 | testa | 12 | jhon | 12
admin added the BugInvalid labels 2026-01-22 15:30:20 +01:00
admin closed this issue 2026-01-22 15:30:20 +01:00
Author
Owner

@lcobucci commented on GitHub (Sep 13, 2019):

@Stijn98s that's expected.

ExpressionBuilder#contains() is converted to age LIKE '%1%', which is invalid for numeric columns (it should even throw an exception on stricter platforms like PGSQL).

I don't think you'll be able to achieve what you want using the Criteria API.

@lcobucci commented on GitHub (Sep 13, 2019): @Stijn98s that's expected. `ExpressionBuilder#contains()` is converted to `age LIKE '%1%'`, which is invalid for numeric columns (it should even throw an exception on stricter platforms like PGSQL). I don't think you'll be able to achieve what you want using the Criteria API.
Author
Owner

@lcobucci commented on GitHub (Sep 13, 2019):

Will close this as invalid as per my explanation. Please reopen if needed.

@lcobucci commented on GitHub (Sep 13, 2019): Will close this as `invalid` as per my explanation. Please reopen if needed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6296