Yii2: Why in the beforeDelete method, does the hasMany return a null? -
i'm trying delete related data has many-to-many relationship my complex model: /** * @return \yii\db\activequery */ public function getcomplexdocument() { return $this->hasmany(complexdocument::classname(), ['complex_id' => 'id']); } /** * @return \yii\db\activequery */ public function getdocuments() { return $this->hasmany(documents::classname(), ['id' => 'document_id']) ->via('complexdocument'); } in beforedelete following: public function beforedelete() { foreach ($this->documents $document){ var_dump($document); } return parent::beforedelete(); } deletion not happen, checked , hasmany connections return null. in debug see following i did way: public function delete() { foreach ($this->documents $document){ $document->delete(); } return parent::delete(); // todo: change autogenerated stub } everything works, related do...