Skip to content

Commit

Permalink
Merge ae1cb25 into 2d99c1e
Browse files Browse the repository at this point in the history
  • Loading branch information
narcoticfresh committed Dec 7, 2015
2 parents 2d99c1e + ae1cb25 commit 33c6ec0
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Doctrine/ODM/MongoDB/Types/StringType.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class StringType extends Type
{
public function convertToDatabaseValue($value)
{
return $value !== null ? (string) $value : null;
return $value !== null ? $value instanceof \MongoRegex ? $value : (string) $value : null;
}

public function convertToPHPValue($value)
Expand Down
52 changes: 52 additions & 0 deletions tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1294Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Doctrine\ODM\MongoDB\Tests\Functional\Ticket;

use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

class GH1294Test extends \Doctrine\ODM\MongoDB\Tests\BaseTest
{
public function testMongoRegexSearchOnIdentifierWithUuidStrategy()
{
$userClass = __NAMESPACE__ . '\GH1294User';

$user1 = new GH1294User();
$user1->id = 'aaa111aaa';
$user1->name = 'Steven';

$user2 = new GH1294User();
$user2->id = 'bbb111bbb';
$user2->name = 'Jeff';

$this->dm->persist($user1);
$this->dm->persist($user2);
$this->dm->flush();
$this->dm->clear();

$qb = $this->dm->createQueryBuilder($userClass);

$res = $qb->field('id')
->equals(new \MongoRegex("/^bbb.*$/i"))
->getQueryArray();

$this->assertTrue(($res['_id'] instanceof \MongoRegex));
$this->assertEquals('^bbb.*$', $res['_id']->regex);
$this->assertEquals('i', $res['_id']->flags);
}
}

/** @ODM\Document */
class GH1294User
{
/** @ODM\Id(strategy="UUID", type="string") */
public $id;

/** @ODM\String */
public $name = false;

// Return the identifier without triggering Proxy initialization
public function getId()
{
return $this->id;
}
}

0 comments on commit 33c6ec0

Please sign in to comment.