petrgrishin/yii-one-side-relation

One side relation behavior

1.0.0 2014-05-26 19:29 UTC

This package is not auto-updated.

Last update: 2024-10-26 16:36:16 UTC


README

Travis CI Coverage Status

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();