In my web application I need to compare the attribute values of two different models
I want to compare the value of attribute named booked_quantity
of a model named BookVegetable
to the value of a attribute named offered_qty
of a model name ProducerOffer
. What I want is the values of booked_quantity
should be lesser or equal to offered_qty but not greater. I tried searching it but no where I found for comparing two different model attribute values.
How should I proceed ? or should I compare it in the controller itself? and generate flash error message?
The code I tried but in vain
public function compareBookedQuantity($booked_quantity,$params){
$count = BookVegetable::model()->findByAttributes(array('booked_quantity'=>$booked_quantity));
if ($count > $this->offered_qty){
$this->addError($booked_quantity,'Please enter a quantity lesser than offered quantity');
}
}
public function rules()
{
return array(
array('offered_qty','compareBookedQuantity'),
);
}
In my form I have values of both models. How should I compare the attribute values ? please help The relations function in ProducerOffer model.
public function relations()
{
return array( 'producerOfferBookVegetableRelation'=>array(self::BELONGS_TO, 'BookVegetable','id'),
);
}