Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/petrgrishin/yii-one-side-relation
One side relation behavior
https://github.com/petrgrishin/yii-one-side-relation
Last synced: 8 days ago
JSON representation
One side relation behavior
- Host: GitHub
- URL: https://github.com/petrgrishin/yii-one-side-relation
- Owner: petrgrishin
- Created: 2014-05-21T20:03:24.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-06-12T08:34:18.000Z (over 10 years ago)
- Last Synced: 2024-11-08T16:16:57.394Z (2 months ago)
- Language: PHP
- Size: 219 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
yii-one-side-relation
=====================
[![Travis CI](https://travis-ci.org/petrgrishin/yii-one-side-relation.png "Travis CI")](https://travis-ci.org/petrgrishin/yii-one-side-relation)
[![Coverage Status](https://coveralls.io/repos/petrgrishin/yii-one-side-relation/badge.png?branch=master)](https://coveralls.io/r/petrgrishin/yii-one-side-relation?branch=master)One side relation behavior
Installation
------------
Add a dependency to your project's composer.json:
```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```php
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
```php
$model = Model::find(1)->one();
$relatedRecords = $model->testRelation->getRelated();
$model->testRelation->addRelated(new RelationModel());
$model->save();
```