<?php
class GroupTopic extends CActiveRecord {
/**
* @return string the associated database table name
*/
public function tableName() {
return '{{group_topics}}';
}
/**
* @return array validation rules for model attributes.
*/
public function rules() {
return array(
array('name, group_id, initiator_id', 'required'),
array('total_posts', 'numerical', 'integerOnly' => true),
array('name', 'length', 'max' => 255),
array('group_id, initiator_id, opponent_id', 'length', 'max' => 10),
array('updated_at', 'safe'),
// The following rule is used by search().
array('id, name, initiated_at, group_id, initiator_id, opponent_id, total_posts, updated_at', 'safe', 'on' => 'search'),
);
}
/**
* @return array relational rules.
*/
public function relations() {
return array(
'posts' => array(self::HAS_MANY, 'Topic', 'topic_id'),
'group' => array(self::BELONGS_TO, 'Group', 'group_id'),
'initiator' => array(self::BELONGS_TO, 'User', 'initiator_id'),
'opponent' => array(self::BELONGS_TO, 'User', 'opponent_id'),
);
}
/**
* Returns the static model of the specified AR class.
* Please note that you should have this exact method in all your CActiveRecord descendants!
* @param string $className active record class name.
* @return Topic the static model class
*/
public static function model($className=__CLASS__) {
return parent::model($className);
}
}