PHP code example of petrgrishin / yii-one-side-relation
1. Go to this page and download the library: Download petrgrishin/yii-one-side-relation library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
petrgrishin / yii-one-side-relation example snippets
use \CActiveRecord as ActiveRecord;
use \PetrGrishin\OneSideRelation\OneSideRelation;
class Model extends ActiveRecord {
public function behaviors() {
return array(
'testRelation' => array(
'class' => OneSideRelation::className(),
'fieldNameStorage' => 'data',
'relationModel' => RelationModel::className(),
)
);
}
}
$model = Model::find(1)->one();
$relatedRecords = $model->testRelation->getRelated();
$model->testRelation->addRelated(new RelationModel());
$model->save();