Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

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

toomuchpete opened this issue Aug 29, 2012 · 2 comments
Labels

Comments

@toomuchpete
Copy link
Contributor

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
Copy link
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
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants