[Solved]Comparing two fields

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.

You’re missing the relation type:

e.g.




public function relations()

{

    return array(

        array( self::BELONGS_TO, 'salary_range_to', 'greater_check' ),

    );

}



Even though no errors are coming…

The validation is not happening…


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');

}



Nope even this change is not bringing any validation.

remove the ‘max’=>16


array('salary_range_from', 'greater_check'),

anyway, it should work

check the values and if you are reaching the method, like




die($this->salary_range_to ." - ". $this->salary_range_from);

if( $this->salary_range_to > $this->salary_range_from)

  //...



yes i am getting the values like

5-10

Sorry… i should change it to


if( $this->salary_range_from > $this->salary_range_to)

;D