Compare Two Vales Before Saving

Hello guys! I am fairy new to yii. So, i have a CActiveForm for bidding on some products. Say i have one product that is named package3 and i am receiving bids for it. I want every bid for that package to be higher than the last made. How can i do that?

My table is named Bids an its columns are:







Please put custom validation in Model - Bids

in rules(){



Function CustomValidation()


// get Higher Bid

// compare higher bids with $this->bid

// return error or true depends on validation


Hello again, thanks for your reply.

Can you be more specific about the customValidation function?

How can i get the highest bid from the database?

what i have in mind is something like:

function customValidation()


    //get all the records of the same packageID

    //find the highest bid from these records

    //compare highest bid with $this->bid

    //return error etc


but i am not sure how to make the first two parts of the function. i have tried a lot of things but nothing worked…

I think that i managed to do it. :rolleyes:

Here is my function:

function customValidation()



            $Criteria = new CDbCriteria();


            $Criteria->condition = "packageID = $packid";

            $Criteria->order = "bid DESC";

            $products = Bids::model()->findAll($Criteria);


            foreach ($products as $value) 


                if ($value->bid>$this->bid)


                   $this->addError('bid', 'some error');





Is it ok? i am not sure. :P