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

save document set in document set #94

Open boulmerhras opened 12 years ago

boulmerhras commented 12 years ago

Hi! I have two Document set : "step": [ { "step": "aller de agadir a essaouira", "deadline": "18-09-2013", "contributor": { "name": "iddriss", "id": "125423165423", "profilImg": "1346665127.jpg" }, "comment": [

                 {
                      "comment": "le deuxieme commentaire",
                       "datec": "10-09-2012 01:09",
                          "author": {
                              "name": "hassan fghghfghfgh",
                                    "id": ObjectId("4ff468a1c3ebd0140b000009"),
                                   "profilImg": "1346665127.jpg"
                                            }
                 },
                 {
                         "comment": "le troixieme commentaire",
                        "datec": "11-09-2012 07:09",
                         "author": {
                          "name": "hassan fghghfghfgh",
                           "id": ObjectId("4ff468a1c3ebd0140b000009"),
                              "profilImg": "1346665127.jpg"
                                          }
                  }
            ],

},
{
  "step": "aller de essaouira a marrakech",
  "deadline": "18-09-2013",
  "contributor": {
    "name": "kamal",
    "id": "125423165423",
    "profilImg": "1346665127.jpg"
      },
        "comment": [

                 {
                      "comment": "comment",
                       "datec": "10-09-2012 01:09",
                          "author": {
                              "name": "hassan fghghfghfgh",
                                    "id": ObjectId("4ff468a1c3ebd0140b000009"),
                                   "profilImg": "1346665127.jpg"
                                            }
                 },
                 {
                         "comment": "comment",
                        "datec": "11-09-2012 07:09",
                         "author": {
                          "name": "hassan fghghfghfgh",
                           "id": ObjectId("4ff468a1c3ebd0140b000009"),
                              "profilImg": "1346665127.jpg"
                                          }
                  }
            ],
}

],

and I have my models : class Application_Model_Objectif extends Shanty_Mongo_Document {

protected static $_db = 'mybpartner'; protected static $_collection = 'objectif'; protected static $_requirements = array( 'comment' => 'DocumentSet', 'commentsc' => 'DocumentSet', 'step' => 'DocumentSet', 'step.$.comment' => 'DocumentSet' ); }

I want to save a new comment in step number 1 (for exemple) I write this code : $row = Application_Model_Objectif::find('50179b9bff48b39c07000000'); $new = $row->step(1)->comment->new(); $new->comment = 'comment'; $new->datec = date('d-m-Y h:m'); $new->author = array('name' => 'hassan', 'id' => '1545fdfdf454df', 'profilImg' => 'img1.jpg' ); $row->step(1)->comment->addDocument($new); }

        $row->save();

but doesn't work!! please help me how can save a new comment ?? and sorry for my english!! thank you,,,