Browse Source

Method "\yii\mogo\Collection::buildLikeCondition()" fixed to use \MongoRegex.

tags/2.0.0-beta
Paul Klimov 11 years ago
parent
commit
8032785f0d
  1. 5
      extensions/mongo/Collection.php
  2. 12
      tests/unit/extensions/mongo/QueryRunTest.php

5
extensions/mongo/Collection.php

@ -907,6 +907,9 @@ class Collection extends Object
throw new InvalidParamException("Operator '$operator' requires two operands.");
}
list($column, $value) = $operands;
return [$column => '/' . $value . '/'];
if (!($value instanceof \MongoRegex)) {
$value = new \MongoRegex($value);
}
return [$column => $value];
}
}

12
tests/unit/extensions/mongo/QueryRunTest.php

@ -129,4 +129,16 @@ class QueryRunTest extends MongoTestCase
->all($connection);
$this->assertEquals(1, count($rows));
}
public function testLike()
{
$connection = $this->getConnection();
$query = new Query;
$rows = $query->from('customer')
->where(['LIKE', 'name', '/me1/'])
->all($connection);
$this->assertEquals(2, count($rows));
$this->assertEquals('name1', $rows[0]['name']);
$this->assertEquals('name10', $rows[1]['name']);
}
}
Loading…
Cancel
Save