"Unique" validation rule for all tables?

Lets say I have tables with similar fields called "code".

Is it possible to verify if the entered value to the "code" field unique to the current table and other tables with the same field using model validation rules?

You should write a custom validation rules.

Just add to the rules a line:




array('code', 'uniqueAmongTables'),



And then write your own validation rule:




public function uniqueAmongTables()

{

   if( condition )

  {

     $this->addError('code is not unique');

  }

}



By the way, if the code has to be unique among many table, maybe you should redesign your database, create a table for this code and then using foreign keys for point from the other tables.

If you think like that, you will have no needs to do such a validation rules.