Mongodb Activerecord

Guys,

I have a Mongodb ActiveRecord.When I try to do this inside of ActiveRecord


 $this->blocks[$block->id]=$block 

I got




Indirect modification of overloaded property app\models\ActiveRecord\Page::$blocks has no effect



I think it’s because properties in ActiveRecords isn’t real properties. So I add a public property to ActiveRecord like this:


 public $blocks = [];

and error has been gone but blocks not saving in Db.

Do you mean that your blocks attribute is actually an embedded document in MongoDB terms?

In that case you may have to use this approach:

MongoDb’s embedded documents mapping for ActiveRecord in Yii2