Skip to content

Commit

Permalink
Fix too much string casting. fixes doctrine#245
Browse files Browse the repository at this point in the history
  • Loading branch information
jwage committed Oct 11, 2012
1 parent befb8e2 commit 8e3cb5b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataInfo.php
Expand Up @@ -1296,7 +1296,7 @@ public function getIdentifierValue($document)
if ($document instanceof Proxy && !$document->__isInitialized()) {
return $document->__identifier__;
}
return (string) $this->reflFields[$this->identifier]->getValue($document);
return $this->reflFields[$this->identifier]->getValue($document);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ODM/MongoDB/Mapping/Types/IdType.php
Expand Up @@ -41,7 +41,7 @@ public function convertToDatabaseValue($value)

public function convertToPHPValue($value)
{
return $value !== null ? (string) $value : null;
return $value instanceof \MongoId ? (string) $value : $value;
}

public function closureToMongo()
Expand All @@ -51,6 +51,6 @@ public function closureToMongo()

public function closureToPHP()
{
return '$return = (string) $value;';
return '$return = $value instanceof \MongoId ? (string) $value : $value;';
}
}
46 changes: 46 additions & 0 deletions tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH245Test.php
@@ -0,0 +1,46 @@
<?php

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

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

class GH245Test extends \Doctrine\ODM\MongoDB\Tests\BaseTest
{
public function testTest()
{
$order = new GH245Order();
$order->id = 1;

$orderLog = new GH245OrderLog();
$orderLog->order = $order;

$this->dm->persist($orderLog);
$this->dm->persist($order);
$this->dm->flush();
$this->dm->clear();

$user = $this->dm->find(get_class($order), $order->id);

$this->assertTrue(is_int($order->id));

$check = $this->dm->getDocumentCollection(get_class($orderLog))->findOne();
$this->assertTrue(is_int($check['order']['$id']));
}
}

/** @ODM\Document */
class GH245Order
{
/** @ODM\Id(strategy="NONE") */
public $id;
}

/** @ODM\Document */
class GH245OrderLog
{
/** @ODM\Id */
public $id;

/** @ODM\ReferenceOne(targetDocument="GH245Order") */
public $order;
}

0 comments on commit 8e3cb5b

Please sign in to comment.