Cactiverecord Rules To Check If Data Already Exists

Dear all,

I am creating new datasets but currently I don´t know how to check it data already exists in the database. I have read the the save() should automatically check the rules function. Is that true?

I think it is not working because the line


array('id_os', 'exists', 'on'=>'insert_post'),

is not good.

I have


	public function actionCreate()

	{

		$model=new Operatingsystem;


		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);


		if(isset($_POST['Operatingsystem']))

		{

			$model->attributes=$_POST['Operatingsystem'];

                        if($model->save())

				$this->redirect(array('view','id'=>$model->id_os));

		}


		$this->render('create',array(

			'model'=>$model,

		));

	}

and this rules function.


	public function rules()

	{

		// NOTE: you should only define rules for those attributes that

		// will receive user inputs.

		return array(

			array('id_os', 'required'),

			array('id_os', 'length', 'max'=>20),

			array('os_name', 'length', 'max'=>45),

			// The following rule is used by search().

			// Please remove those attributes that should not be searched.

			array('id_os, os_name', 'safe', 'on'=>'search'),

                        array('id_os', 'exists', 'on'=>'insert_post'),

		);

	}

Hi,

I found the solution. The rule is


array('id_os', 'unique'),

Thanks , it worked