Permalink
Browse files

Merge pull request #791 from myclabs/CriteriaContains

Implemented "contains" operator for Criteria expressions
  • Loading branch information...
2 parents ded3d20 + 6f538c5 commit be81b46d8ee7fcb01741ec9f64656602f3c4436a @guilhermeblanco guilhermeblanco committed Oct 11, 2013
View
5 lib/Doctrine/ORM/Query/QueryExpressionVisitor.php
@@ -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) {
View
2 tests/Doctrine/Tests/ORM/Query/QueryExpressionVisitorTest.php
@@ -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')),
);

0 comments on commit be81b46

Please sign in to comment.