1
0
mirror of synced 2024-12-13 14:56:01 +03:00

Merge pull request #791 from myclabs/CriteriaContains

Implemented "contains" operator for Criteria expressions
This commit is contained in:
Guilherme Blanco 2013-10-11 06:33:40 -07:00
commit be81b46d8e
2 changed files with 7 additions and 0 deletions

View File

@ -154,6 +154,11 @@ class QueryExpressionVisitor extends ExpressionVisitor
$this->parameters[] = $parameter;
return $this->expr->neq($comparison->getField(), $placeholder);
case Comparison::CONTAINS:
$parameter->setValue('%' . $parameter->getValue() . '%', $parameter->getType());
$this->parameters[] = $parameter;
return $this->expr->like($comparison->getField(), $placeholder);
default:
$operator = self::convertComparisonOperator($comparison->getOperator());
if ($operator) {

View File

@ -85,6 +85,8 @@ class QueryExpressionVisitorTest extends \PHPUnit_Framework_TestCase
array($cb->in('field', array('value')), $qb->in('field', ':field'), new Parameter('field', array('value'))),
array($cb->notIn('field', array('value')), $qb->notIn('field', ':field'), new Parameter('field', array('value'))),
array($cb->contains('field', 'value'), $qb->like('field', ':field'), new Parameter('field', '%value%')),
// Test parameter conversion
array($cb->eq('object.field', 'value'), $qb->eq('object.field', ':object_field'), new Parameter('object_field', 'value')),
);