yii-one-side-relation One side relation activerecord behavior

  1. Installation
  2. Usage examples

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();
1 0
1 follower
152 downloads
Yii Version: 1.1
License: MIT
Category: Database
Developed by: Petr.Grishin
Created on: May 26, 2014
Last updated: 10 years ago

Downloads

show all

Related Extensions