Skip to content

Commit

Permalink
Merge branch '1.0.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
malarzm committed Jul 27, 2016
2 parents 626f5f6 + 06c4cad commit 4aa45f5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/Doctrine/ODM/MongoDB/Hydrator/HydratorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,13 @@ private function generateHydratorClass(ClassMetadata $class, $hydratorClassName,
$code .= sprintf(<<<EOF
/** @Field(type="{$mapping['type']}") */
if (isset(\$data['%1\$s'])) {
if (isset(\$data['%1\$s']) || (! empty(\$this->class->fieldMappings['%2\$s']['nullable']) && array_key_exists('%1\$s', \$data))) {
\$value = \$data['%1\$s'];
%3\$s
if (\$value !== null) {
%3\$s
} else {
\$return = null;
}
\$this->class->reflFields['%2\$s']->setValue(\$document, \$return);
\$hydratedData['%2\$s'] = \$return;
}
Expand Down
5 changes: 5 additions & 0 deletions tests/Doctrine/ODM/MongoDB/Tests/HydratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public function testHydrator()
$user = new HydrationClosureUser();
$this->dm->getHydratorFactory()->hydrate($user, array(
'_id' => 1,
'title' => null,
'name' => 'jon',
'birthdate' => new \DateTime('1961-01-01'),
'referenceOne' => array('$id' => '1'),
Expand All @@ -32,6 +33,7 @@ public function testHydrator()
));

$this->assertEquals(1, $user->id);
$this->assertSame(null, $user->title);
$this->assertEquals('jon', $user->name);
$this->assertInstanceOf('DateTime', $user->birthdate);
$this->assertInstanceOf(__NAMESPACE__.'\HydrationClosureReferenceOne', $user->referenceOne);
Expand Down Expand Up @@ -70,6 +72,9 @@ class HydrationClosureUser
/** @ODM\Id */
public $id;

/** @ODM\Field(type="string", nullable=true) */
public $title = 'Mr.';

/** @ODM\Field(type="string") */
public $name;

Expand Down

0 comments on commit 4aa45f5

Please sign in to comment.