Просмотр файла vkclone-0.0.1/protected/models/ForumSection.php

Размер файла: 1.36Kb
<?php
/**
 * This is the model class for table "{{forum_sections}}".
 */
class ForumSection extends CActiveRecord {

	/**
	 * @return string the associated database table name
	 */
	public function tableName() {
		return '{{forum_sections}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules() {
		return array(
			array('name, forum_id', 'required'),
			array('total_topics', 'numerical', 'integerOnly' => true),
			array('name', 'length', 'max' => 255),
			array('forum_id', 'length', 'max' => 10),
			array('updated_at', 'safe'),
			// The following rule is used by search().
			array('id, name, forum_id, total_topics, updated_at', 'safe', 'on' => 'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations() {
		return array(
			'topics' => array(self::HAS_MANY, 'Topic', 'section_id'),
			'forum' => array(self::BELONGS_TO, 'Forum', 'forum_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 ForumSection the static model class
	 */
	public static function model($className=__CLASS__) {
		return parent::model($className);
	}

	public function defaultScope() {
		return array(
			'order' => 'total_topics DESC',
		);
	}
}