Skip to content

Commit

Permalink
Stop type conversion for certain keys in query
Browse files Browse the repository at this point in the history
  • Loading branch information
malarzm committed Jun 26, 2020
1 parent 96d95b1 commit 53fa39d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,10 @@ private function convertToDatabaseValue(string $fieldName, $value)
{
if (is_array($value)) {
foreach ($value as $k => $v) {
if ($k === '$exists' || $k === '$type' || $k === '$currentDate') {
continue;
}

$value[$k] = $this->convertToDatabaseValue($fieldName, $v);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Doctrine\ODM\MongoDB\Tests\BaseTest;
use Doctrine\ODM\MongoDB\Types\ClosureToPHP;
use Doctrine\ODM\MongoDB\Types\Type;
use Documents\Article;
use Generator;
use InvalidArgumentException;
use MongoDB\BSON\ObjectId;
Expand Down Expand Up @@ -140,6 +141,33 @@ public function getTestPrepareFieldNameData()
];
}

public function testCurrentDateInQuery()
{
$qb = $this->dm->createQueryBuilder(Article::class)
->updateMany()
->field('createdAt')->currentDate();

$this->assertSame(
['$currentDate' => ['createdAt' => ['$type' => 'date']]],
$qb->getQuery()->debug('newObj')
);
}

public function testExistsInQuery()
{
$qb = $this->dm->createQueryBuilder(Article::class)
->field('title')->exists(false)
->field('createdAt')->exists(true);

$this->assertSame(
[
'title' => ['$exists' => false],
'createdAt' => ['$exists' => true],
],
$qb->getQuery()->debug('query')
);
}

/**
* @dataProvider provideHashIdentifiers
*/
Expand Down

0 comments on commit 53fa39d

Please sign in to comment.