Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.0.0ALPHA2
    • Component/s: Hydration
    • Labels:
      None

      Description

      I'm working on a project using MongoDB with ODM especially for the schemaless features.
      So I have one collection with some default fields in my base class.
      Every inherited class add fields but we're still in the same collection.

      First, prior to save the document, I add the new mappings (imported from the inherited class) so they will be saved in the database. This part works fine.
      The problem is that when the ODM hydrates the documents, it sticks to the $metadata->fieldMappings defined by the base class, and ignore the others.

      I've made a quick patch for that, but it doesn't make any type cast, I didn't inspect the code deep enough to make it better.

      In the Doctrine\ODM\MongoDB\Hydrator class (line 73) :

          public function hydrate(ClassMetadata $metadata, $document, $data)
          {
              $values = array();
      
              // Patch
              foreach ($data as $field => $value)
              {
                if(!array_key_exists($field, $metadata->fieldMappings))
                {
                  $document->$field = $value;
                }
              }
              // end Patch
      
              foreach ($metadata->fieldMappings as $mapping) {
      [...]
      
      

        Activity

        Anonymous created issue -
        Jonathan H. Wage made changes -
        Field Original Value New Value
        Description I'm working on a project using MongoDB with ODM especially for the schemaless features.
        So I have one collection with some default fields in my base class.
        Every inherited class add fields but we're still in the same collection.

        First, prior to save the document, I add the new mappings (imported from the inherited class) so they will be saved in the database. This part works fine.
        The problem is that when the ODM hydrates the documents, it sticks to the $metadata->fieldMappings defined by the base class, and ignore the others.

        I've made a quick patch for that, but it doesn't make any type cast, I didn't inspect the code deep enough to make it better.

        In the Doctrine\ODM\MongoDB\Hydrator class (line 73) :

            public function hydrate(ClassMetadata $metadata, $document, $data)
            {
                $values = array();

                // Patch
                foreach ($data as $field => $value)
                {
                  if(!array_key_exists($field, $metadata->fieldMappings))
                  {
                    $document->$field = $value;
                  }
                }
                // end Patch

                foreach ($metadata->fieldMappings as $mapping) {
        [...]
        I'm working on a project using MongoDB with ODM especially for the schemaless features.
        So I have one collection with some default fields in my base class.
        Every inherited class add fields but we're still in the same collection.

        First, prior to save the document, I add the new mappings (imported from the inherited class) so they will be saved in the database. This part works fine.
        The problem is that when the ODM hydrates the documents, it sticks to the $metadata->fieldMappings defined by the base class, and ignore the others.

        I've made a quick patch for that, but it doesn't make any type cast, I didn't inspect the code deep enough to make it better.

        In the Doctrine\ODM\MongoDB\Hydrator class (line 73) :

        {code}
            public function hydrate(ClassMetadata $metadata, $document, $data)
            {
                $values = array();

                // Patch
                foreach ($data as $field => $value)
                {
                  if(!array_key_exists($field, $metadata->fieldMappings))
                  {
                    $document->$field = $value;
                  }
                }
                // end Patch

                foreach ($metadata->fieldMappings as $mapping) {
        [...]

        {code}
        Hide
        Jonathan H. Wage added a comment -

        This is fixed now. Make sure your classes inheritance mapping is setup properly too if you have other problems.

        Show
        Jonathan H. Wage added a comment - This is fixed now. Make sure your classes inheritance mapping is setup properly too if you have other problems.
        Jonathan H. Wage made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 1.0.0ALPHA2 [ 10065 ]
        Resolution Fixed [ 1 ]

        This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

        • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=MODM-24, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

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

            Dates

            • Created:
              Updated:
              Resolved: