Note that there are some explanatory texts on larger screens.

plurals
  1. POUpsert embedded document in yiimongodbsuite
    primarykey
    data
    text
    <p>I need to perform an upsert command in yiimongodbsuite. I tried </p> <pre><code>$model = new Murls(); $model-&gt;userid=$userid; $model-&gt;title=$title; $model-&gt;edits[0] = new Medithtml(); $model-&gt;edits[0]-&gt;path= $htm; $model-&gt;edits[0]-&gt;html=$path; $model-&gt;edits[0]-&gt;ci=$ci; $model-&gt;update(array('_id'=&gt;$rec-&gt;_id ),array('userid', 'title','edits' ), true ); </code></pre> <p>But this shows an error.</p> <p>Murls model is defined as follows</p> <pre><code> class Murls extends EMongoDocument { public $userid; public $title; public $edits; public static function model($className=__CLASS__) { return parent::model($className); } // This method is required! public function getCollectionName() { return 'murls'; } public function attributeLabels() { return array( 'html'=&gt;'Html', ); } public function embeddedDocuments() { return array( // property name =&gt; embedded document class name 'edits'=&gt;'Medithtml', ); } public function behaviors(){ return array( 'embeddedArrays' =&gt; array( 'class' =&gt; 'ext.YiiMongoDbSuite.extra.EEmbeddedArraysBehavior', 'arrayPropertyName' =&gt; 'edits', // name of property, that will be used as an array 'arrayDocClassName' =&gt; 'Medithtml' // class name of embedded documents in array ), ); } } </code></pre> <p>and model Medithtml as </p> <pre><code>class Medithtml extends EMongoEmbeddedDocument{ public $html; public $path; public $ci; public static function model($className=__CLASS__) { return parent::model($className); } } </code></pre> <p>What I need to achieve is that a record with <code>$title</code> can have n number of <code>$html</code> , <code>$path</code> and <code>$ci</code>. Any help will be appreciated. What I am looking is to store data like this</p> <pre><code> array ( '_id' =&gt; MongoId::__set_state(array( '$id' =&gt; '51ee1956d39c2c7e078d80da', )), 'userid' =&gt; '12', 'title' =&gt; 'Mongo', 'edits' =&gt; array ( 0 =&gt; array ( 'html' =&gt; 'html&gt;body&gt;div:nth-child(2)&gt;a&gt;div&gt;a&gt;div', 'path' =&gt; 'ssssss', 'ci' =&gt; '1', ), 1 =&gt; array ( 'html' =&gt; 'html&gt;body&gt;div:nth-child(2)&gt;a&gt;div:nth-child(3)&gt;a&gt;h2', 'path' =&gt; '/assets/img/demo/demo-avatar9604.jpg', 'ci' =&gt; '2', ), 2 =&gt; array ( 'html' =&gt; ' html&gt;body&gt;div:nth-child(2)&gt;a&gt;div:nth-child(3)&gt;a&gt;center:nth-child(16)&gt;a&gt;h1', 'path' =&gt; '333', 'ci' =&gt; '3', ), ), ) </code></pre> <p>Only the comments array will be updated if record with a particular combination of <code>'title'</code> and <code>'userid'</code> exists.If it doesn not exists a new record will be inserted</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload