-
-
Notifications
You must be signed in to change notification settings - Fork 505
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix query preparation when in elemMatch (#2299)
- Loading branch information
Showing
2 changed files
with
109 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1674Test.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\ODM\MongoDB\Tests\Functional\Ticket; | ||
|
||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; | ||
use Doctrine\ODM\MongoDB\Tests\BaseTest; | ||
use MongoDB\BSON\ObjectId; | ||
|
||
class GH1674Test extends BaseTest | ||
{ | ||
public function testElemMatchUsesCorrectMapping() | ||
{ | ||
$builder = $this->dm->createQueryBuilder(GH1674Document::class); | ||
$builder | ||
->field('embedded') | ||
->elemMatch( | ||
$builder->expr() | ||
->field('id') | ||
->equals(1) | ||
); | ||
|
||
$this->assertSame( | ||
[ | ||
'embedded' => [ | ||
'$elemMatch' => ['id' => '1'], | ||
], | ||
], | ||
$builder->getQueryArray() | ||
); | ||
} | ||
} | ||
|
||
/** @ODM\Document */ | ||
class GH1674Document | ||
{ | ||
/** @ODM\Id */ | ||
protected $id; | ||
|
||
/** @ODM\EmbedMany(targetDocument=GH1674Embedded::class) */ | ||
protected $embedded; | ||
|
||
public function __construct() | ||
{ | ||
$this->id = new ObjectId(); | ||
$this->embedded = new ArrayCollection(); | ||
} | ||
} | ||
|
||
/** @ODM\EmbeddedDocument */ | ||
class GH1674Embedded | ||
{ | ||
/** @ODM\Field */ | ||
public $id = []; | ||
} |