Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #791 from myclabs/CriteriaContains

Implemented "contains" operator for Criteria expressions
  • Loading branch information...
commit be81b46d8ee7fcb01741ec9f64656602f3c4436a 2 parents ded3d20 + 6f538c5
Guilherme Blanco guilhermeblanco authored
5 lib/Doctrine/ORM/Query/QueryExpressionVisitor.php
View
@@ -154,6 +154,11 @@ public function walkComparison(Comparison $comparison)
$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) {
2  tests/Doctrine/Tests/ORM/Query/QueryExpressionVisitorTest.php
View
@@ -85,6 +85,8 @@ public function comparisonData()
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')),
);
Please sign in to comment.
Something went wrong with that request. Please try again.