Installation ¶
Add a dependency to your project's composer.json:
https://github.com/petrgrishin/yii-one-side-relation/
{
"require": {
"petrgrishin/yii-one-side-relation": "~1.0"
}
}
Usage examples ¶
Attach behavior to you model ¶
Model have text attribute data
for storage relational data
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(),
)
);
}
}
Usage behavior ¶
$model = Model::find(1)->one();
$relatedRecords = $model->testRelation->getRelated();
$model->testRelation->addRelated(new RelationModel());
$model->save();
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.