I want to compare two fields. For checking if the second field is greater than the first field.
After going through some forum topics,i finally did this coding in my model
public function greater_check($attribute,$params)
{
if( $this->salary_range_to > $this->salary_range_from)
$this->addError('salary_range_to','Should be higher value');
}
public function rules()
{
array('salary_range_from,salary_range_to', 'length', 'max'=>16),
}
public function relations()
{
return array(
array('salary_range_to', 'greater_check'),
);
}
I am getting a error…
Active record "PsmsOrderSkillitemDetail" has an invalid configuration for relation "0". It must specify the relation type, the related active record class and the foreign key.
public function rules(){
array('salary_range_from,salary_range_to', 'length', 'max'=>16),
array('salary_range_from', 'greater_check', 'max'=>16),
}
public function greater_check()
{
if( $this->salary_range_to > $this->salary_range_from)
$this->addError('salary_range_to','Should be higher value');
}