sokil / php-mongo

MongoDB ODM. Part of @PHPMongoKit
http://phpmongokit.github.io/
MIT License
242 stars 46 forks source link

pushing a dict into an array results in array in array #132

Closed carpio88 closed 8 years ago

carpio88 commented 8 years ago

After updating from a fairly old version (1.12.x) to 1.19 yesterday, I've expirenced some issues with the push function.

When I push a dictionary into an array which already has one element, the added value will be transformed from a dictionary to an array.

e.g. the current situation in the DB document looks like this:

{
...
array : [
    {
        "data" : {}, 
        "since" : NumberLong(1444640066), 
        "until" : NumberLong(1475744066), 
        "addFilter" : {}, 
        "refreshtime" : NumberLong(1475744066)
    }
]
} 

a new element should be added to the array with the same structure by using the doc->push() function, as follows:

$dataset = [
                    'data' => [...],
                    'since' => time(),
                    'until' => time(),
                    'addFilter' => [...],
                    'refreshtime' => time()
                ];

$doc->push( 'array', $dataset );

the result is the following structure

{
...
array : [
    {
        "data" : {}, 
        "since" : NumberLong(1444640066), 
        "until" : NumberLong(1475744066), 
        "addFilter" : {}, 
        "refreshtime" : NumberLong(1475744066)
    },
    [
        {},
        NumberLong(1444640066), 
        NumberLong(1444640066), 
        {},
        NumberLong(1444640066), 
    ]
]
} 

I would appreciate your help with this. thanks a lot in advance.

sokil commented 8 years ago

yes. bug is reproduced. will be fixed soon

sokil commented 8 years ago

this might was there from begining: https://github.com/sokil/php-mongo/blob/1.12.0/src/Operator.php#L36-L38

it was ptotection from passing modifiers o_O https://github.com/sokil/php-mongo/commit/8d23d7c3b5beef44133b82ac1b035fc85d581a48 added in v.1.6.3

sokil commented 8 years ago

may you check your code on branch "test_push"? I'll cover more cases soon and marge to master, if all will be good.

carpio88 commented 8 years ago

thanks for your fast reply. I've tested your code from the branch. So far it's working fine :+1:

sokil commented 8 years ago

ok. i'l do more tests and merge it tommorow. thenk you for bug report