Yii 1.1: yii-relationvalidator

RelationValidator sets relation return value in the .rules() specified field.
6 followers

RelationValidator sets relation return value in the .rules() specified field.

It helps avoid making redundant methods for setting values, returned by STAT-relations, in the AR-fileds. Or you may think up your own use cases.

Current version is always here: https://github.com/pavel-voronin/yii-RelationValidator/.

Requirements

  • Yii Framework (any version)

Install

Clone yii-RelationValidator from github:

cd protected/extensions
git clone git://github.com/pavel-voronin/yii-RelationValidator.git

Put next strings in protected/config/main.php:

'import' => array
(
    'ext.yii-RelationValidator.RelationValidator'
),

Usage

class Post extends CActiveRecord
{
    // ...
 
    public function rules ( )
    {
        return array
        (
            array
            (
                'post_rating',
                'RelationValidator',
                'relation' => 'post_rating', // relation name from ::relations()
                'forceRefresh' => false, // whether to fully reload specified relation
                'except' => 'insert'
            ),
        );
    }
 
    public function relations ( )
    {
        return array
        (
            'post_rating' => array ( self::STAT, 'PostVotes', 'post_id', 'select' => 'SUM(vote)' )
        );
    }
 
    // ...
}

Changelog

version 1.0

  • Initial version. Works great.

Total 2 comments

#11537 report it
Pavel Voronin at 2013/01/19 06:31am
English version

Voila! :)

P.S.: There was simple russian.

#11534 report it
robregonm at 2013/01/18 04:13pm
In english, please

Could you please translate your extension to english? That way, the extension will be available to all community.

Leave a comment

Please to leave your comment.

Create extension
Downloads
No downloadable files yet