Issue Details (XML | Word | Printable)

Key: MODM-24
Type: Improvement Improvement
Status: Resolved Resolved
Resolution: Fixed
Priority: Minor Minor
Assignee: Jonathan H. Wage
Reporter: Anonymous
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Doctrine MongoDB ODM

Hydratation of extra fields

Created: 06/Jul/10 05:14 AM   Updated: 19/Jul/10 11:15 PM
Component/s: Hydration
Affects Version/s: None
Fix Version/s: 1.0.0ALPHA2


 Description  « Hide
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) {
[...]


 All   Comments   Change History   FishEye      Sort Order: Ascending order - Click to sort in descending order
Jonathan H. Wage added a comment - 19/Jul/10 11:15 PM
This is fixed now. Make sure your classes inheritance mapping is setup properly too if you have other problems.