1 : <?php
2 :
3 :
4 :
5 :
6 :
7 :
8 :
9 :
10 :
11 : class BasicRelationsMain extends RelationsActiveRecord {
12 :
13 :
14 :
15 :
16 : public static function model($className=__CLASS__) {
17 3 : return parent::model($className);
18 : }
19 :
20 :
21 :
22 :
23 : public function tableName() {
24 8 : return 'tbl_basic_relations_main';
25 : }
26 :
27 :
28 :
29 :
30 : public function rules() {
31 : return array(
32 7 : array ('column_belongs_to_id, column_main_content', 'required'),
33 7 : array ('column_belongs_to_id', 'numerical', 'integerOnly' => true),
34 7 : array ('column_belongs_to_id', 'validBelongsToID'),
35 7 : array ('column_main_content', 'length', 'max' => 255),
36 7 : array ('magic_attribute_many_many_selected', 'safe'),
37 7 : array ('id, column_belongs_to_id, column_main_content', 'safe', 'on' => 'search'),
38 7 : );
39 : }
40 :
41 :
42 :
43 :
44 : public function relations() {
45 : return array(
46 4 : 'relation_belongs_to' => array (self::BELONGS_TO, 'BasicRelationsBelongsTo', 'column_belongs_to_id'),
47 4 : 'relation_has_one' => array (self::HAS_ONE, 'BasicRelationsHasOne', 'column_main_id'),
48 4 : 'relation_has_many' => array (self::HAS_MANY, 'BasicRelationsHasMany', 'column_main_id'),
49 4 : 'relation_many_many' => array (self::MANY_MANY, 'BasicRelationsManyMany', 'tbl_basic_relations_pivot(column_main_id, column_many_many_id)'),
50 4 : );
51 : }
52 :
53 :
54 :
55 :
56 : public function many_many_map () {
57 : return array (
58 : 'relation_many_many' => array (
59 2 : 'class' => 'BasicRelationsPivot',
60 : 'attribute' => 'magic_attribute_many_many_selected'
61 2 : ),
62 2 : );
63 : }
64 :
65 :
66 :
67 :
68 : public function attributeLabels() {
69 : return array(
70 6 : 'id' => 'ID',
71 6 : 'column_belongs_to_id' => 'Column Belongs To ID',
72 6 : 'column_main_content' => 'Column Main Content',
73 6 : );
74 : }
75 :
76 :
77 :
78 :
79 :
80 : public function search() {
81 1 : $criteria=new CDbCriteria;
82 :
83 1 : $criteria->compare('id',$this->id);
84 1 : $criteria->compare('column_belongs_to_id',$this->column_belongs_to_id);
85 1 : $criteria->compare('column_main_content',$this->column_main_content,true);
86 :
87 1 : return new CActiveDataProvider('BasicRelationsMain', array(
88 1 : 'criteria'=>$criteria,
89 1 : ));
90 : }
91 :
92 :
93 :
94 :
95 :
96 :
97 :
98 :
99 :
100 : public function validBelongsToID ($attribute, $params) {
101 :
102 6 : if (isset ($this->errors) && isset ($this->errors[$attribute]))
103 6 : return;
104 : $t_params=array (
105 4 : '{attribute}' => $this->getAttributeLabel($attribute),
106 4 : '{attribute_value}' => $this->$attribute,
107 4 : '{basic_relations_belongs_to_table}' => BasicRelationsBelongsTo::tableName(),
108 4 : );
109 4 : if (!BasicRelationsBelongsTo::model()->idPresent ($this->$attribute))
110 4 : $this->addError ($attribute, Yii::t ('basic_relations', 'The {attribute} of \'{attribute_value}\' does not exist in the {basic_relations_belongs_to_table} table.', $t_params));
111 4 : }
112 :
113 :
114 :
115 :
116 :
117 :
118 :
119 :
120 : public function getMagic_Attribute_Many_Many_Selected () {
121 2 : return $this->magicRelationManyManySelectedRead ('relation_many_many');
122 : }
123 :
124 :
125 :
126 :
127 : public function setMagic_Attribute_Many_Many_Selected ($selected_list) {
128 2 : $this->magicRelationManyManySelectedWrite ('relation_many_many', $selected_list);
129 2 : }
130 : }
|