petrgrishin / yii-one-side-relation
One side relation behavior
1.0.0
2014-05-26 19:29 UTC
Requires
- php: >=5.3.0
- petrgrishin/yii-array-field: ~1.0
- yiisoft/yii: *
Requires (Dev)
This package is not auto-updated.
Last update: 2024-11-23 16:57:19 UTC
README
One side relation behavior
Installation
Add a dependency to your project's composer.json:
{ "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();