Doctrine MongoDB ODM
  1. Doctrine MongoDB ODM
  2. MODM-102

Documents which belong to global namespace can not be handled?

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major 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.

        Activity

        Hide
        Jonathan H. Wage added a comment -

        When you omit the starting \ does that help? I don't think you need to include it.

        Show
        Jonathan H. Wage added a comment - When you omit the starting \ does that help? I don't think you need to include it.
        Hide
        Vitaliy Kaplich added a comment -

        Ok. I'll keep in mind and try later when it become possible and let you know about the result.

        > I don't think you need to include it.

        Unfortunately right now I just can not check it.

        Show
        Vitaliy Kaplich added a comment - Ok. I'll keep in mind and try later when it become possible and let you know about the result. > I don't think you need to include it. Unfortunately right now I just can not check it.

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Vitaliy Kaplich
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: