Arrays of MongoIds are sometimes stored as arrays of strings #623

Closed
toomuchpete opened this Issue Aug 29, 2012 · 2 comments

3 participants

@toomuchpete

Lithium MongoDB entities seem incapable of saving an array of MongoIds to existing records. They handle saving to new records just fine, but fail to update properly.

http://pastium.org/view/149cbf058975c2d55d2b36cfd7bf4c60

In that paste, Widgets is an empty model. Originally, line 6 was commented out and line 3 was active. That produces the first mongo output. For the second run, line 3 was commented out and line 6 was active.

@nateabele
Union of RAD member

Test from paste:


<?php
            // Create New
            // $something = \app\models\Widgets::create();

            // Load Original
            $something = \app\models\Widgets::find('503d149a5b96b8ec33000003');

            $something->save(array('x' => array(new \MongoId(), new \MongoId(), new \MongoId())));
?>

// After create
> db.widgets.findOne();
{
    "_id" : ObjectId("503d149a5b96b8ec33000003"),
    "x" : [
        ObjectId("503d149a5b96b8ec33000000"),
        ObjectId("503d149a5b96b8ec33000001"),
        ObjectId("503d149a5b96b8ec33000002")
    ]
}

// After load and save
> db.widgets.findOne();
{
    "_id" : ObjectId("503d149a5b96b8ec33000003"),
    "x" : [
        "503d14d95b96b8154d000002",
        "503d14d95b96b8154d000003",
        "503d14d95b96b8154d000004"
    ]
}
> 
@rmarscher

I actually discovered this recently and have a patch. Just submitted a pull request for it.

The main problem is that when lithium\util\Collection calls ->to('array') on sub-objects, it doesn't pass through the handlers that are used by the MongoDb Exporter that preserves MongoId and MongoDate objects.

@nateabele nateabele added a commit that closed this issue Sep 13, 2012
@nateabele nateabele Ensuring Mongo object arrays don't get stored as strings, fixes #623.…
… Implementing schema null value support, fixes #629.
7bc8e25
@nateabele nateabele closed this in 7bc8e25 Sep 13, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment