Fetching a value from DB, cached


First of all let me say I Love Yii so far! Great job and i will definitly keep using this!

Now heres my problem:

I’m trying to validate a certain value in a function in one of my controllers.

the function performs a find, using the related model, and i fetch the values ID by querying its name.

I’ll show you the code, it will make things easyer:

        private function fetchValueId($value){

            // Check database if value exists

            $model = DataBase::model()->find(


                        'criteria' => array(

                            'select' => 'id',

                            'condition' => array('name' => $value),




            echo $model->getAttribute('id');


So this works fine when a valid value is submitted for example is have the value ‘value1’ which exists in the table, and has ID 1.

If i then put in the bogus value ‘bogus’ which doesnt exist in the table, the function returns 1, the attribute value of value1.

How can I overcome this? basically its cacheing somewhere or something, what i don’t want in this function

Thanks in advance


I expected the result to be a false or something for the bogus value

Hi, i already fixed it by using findByAttributes!