coen-hyde / Shanty-Mongo

Shanty Mongo is a mongodb library for the Zend Framework. Its intention is to make working with mongodb documents as natural and as simple as possible. In particular allowing embedded documents to also have custom document classes.
Other
200 stars 52 forks source link

Different behaviour of saving embed document #104

Open quard8 opened 11 years ago

quard8 commented 11 years ago

I have my requirements

        'pls'   => array('DocumentSet'),
        'pls.$' => array('Document:Model_Playlist', 'AsReference'),

For example then I saving only "pls" document

$this->pls = new Shanty_Mongo_DocumentSet();
$this->pls->addDocument($playlist);
$this->pls->save();

Resulting JSON representation in DB will be

{
    "pls": {
        "0": {
            "$ref": "playlists",
            "$id": ObjectId("400000000000000000000001")
        }
    }
}

But when I will save all document via $this->save()

I will get

{
    "pls": [
        {
            "$ref": "playlists",
            "$id": ObjectId("400000000000000000000001")
        }
    ]
}

Seem's like a bug, but maybe I'm wrong?

coen-hyde commented 11 years ago

This is a known bug with Shany Mongo. It's caused by php munting the data types after first save. As in your dataset is getting saved as an array, pulled out as a document then resaved as a document. I'm going to try an fix this.