2012-06-18 6 views

Odpowiedz

7

można wykorzystywać własność className określić dla innych klas ..

Dokumentacja: the ActiveRecord class name that should be used to look for the attribute value being validated. Defaults to null, meaning using the class of the object currently being validated. You may use path alias to reference a class name here.

Pozwala mieć atrybut o nazwie common_attr w dwóch modelach:

class Model1 extends CActiveRecord{ 
    public function rules(){ 
     array('common_attr', 'unique', 'className'=> 'Model1'), 
     array('common_attr', 'unique', 'className'=> 'Model2'), 
    } 
} 

class Model2 extends CActiveRecord{ 
    public function rules(){ 
     array('common_attr', 'unique', 'className'=> 'Model1'), 
     array('common_attr', 'unique', 'className'=> 'Model2'), 
    } 
} 

i sprawdzić combined key sprawdzanie poprawności z wielu tabel można użyć właściwości kryterium CUniqueValidator ..Nie potrzeba żadnego rozszerzenia

Dokumentacja: criteria property public array $criteria; additional query criteria. This will be combined with the condition that checks if the attribute value exists in the corresponding table column. This array will be used to instantiate a CDbCriteria object.

class Model1 extends CActiveRecord{ 

    public function rules(){ 
     array('common_attr', 'unique', 'caseSensitive'=>false, 
        'criteria'=>array(
      'join'=>'LEFT JOIN model2 ON model2.common_attr=model1.common_attr', 
          'condition'=>'model2.common_attr=model1.common_attr', 
     )), 
    } 
} 
+0

Pierwsza metoda działa jak czar. Dzięki :) – dInGd0nG

Powiązane problemy