Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Cannot Reproduce
-
Affects Version/s: 1.0.0BETA2
-
Fix Version/s: None
-
Component/s: Hydration
-
Labels:None
-
Environment:CentOS 5.5, PHP 5.3.3
Description
I'm using xml files to store documents annotations.
All my documents are in global namespace.
So lets say I created the following configuration file:
.Blackboard_Page.dcm.xml
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mongo-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mongo-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mongo-mapping.xsd">
<document name="\Blackboard_Page" collection="blackboard.pages">
<field fieldName="_id" name="_id" id="true"/>
...
</document>
</doctrine-mongo-mapping>
When I try to get the document using the following code:
foreach($dm->createQueryBuilder("\Blackboard_Page")...>getQuery()>execute() as $page) {}
it fails with Exception "Doctrine\ODM\MongoDB\MongoDBException: No identifier/primary key specified for Document 'Blackboard_Page'. Every Document must have an identifier/primary key."
The reason of the problem is behavior of the function "get_class".
See mongodb_odm\lib\Doctrine\ODM\MongoDB\Hydrator.php line 122:
$metadata = $this->dm->getClassMetadata(get_class($document));
for details.
When the code pass an instance of the document which belongs to global namespace the function "get_class()" returns class name without "\" prefix
and AbstractFileDriver->findMappingFile convert such class name into file name without leading dot (".") (something like "Blackboard_Page.dcm.xml" instead of ".Blackboard_Page.dcm.xml").
And it causes the exception.
Patching of the method "AbstractFileDriver->findMappingFile" does not help.
The problem is more complicated than it looks like because get_class() is used in a lot of places in the code.
When you omit the starting \ does that help? I don't think you need to include it.