CUniqueValidator problem

hi , I have this table


  `id` int(11) NOT NULL auto_increment,

  `fk_cuota_def_anual_id` int(11) NOT NULL,

  `tipo_cuota` enum('M','A') NOT NULL,

  `mes_calendario` int(11) NOT NULL,

  `vigencia_desde` date NOT NULL,

  `fk_cuenta_contable_id` int(11) NOT NULL,

  `descripcion` varchar(55) character set latin1 collate latin1_spanish_ci NOT NULL default '',

  PRIMARY KEY  (`id`),

  UNIQUE KEY `fk_cuota_def_anual_id` (`fk_cuota_def_anual_id`,`tipo_cuota`,`mes_calendario`),

  KEY `fk_cuenta_contable` (`fk_cuenta_contable_id`)

) ENGINE=InnoDB  DEFAULT CHARSET=latin1 COMMENT='Definicion de Cuotas ' AUTO_INCREMENT=3 ;

As youcan see, I have a UNIQUE contraint.

my model have this on rules:


array('fk_cuota_def_anual_id,tipo_cuota, mes_calendario', 'unique'),


When I update a Record, yii showsme the errro that the id was allready taken.

When is an update the query shoul validate that the unique values are from onother ID, I mean if I’m editin some record, is ok that exist that field value combination, because is the same record…

Any idea what I’m doing wrong …

Best regards


I added ‘on’ but I’m sure if is what I need:

array('fk_cuota_def_anual_id,tipo_cuota, mes_calendario', 'unique', 'on'=>'create'),

at least I have no error when updating, I also readonly fields with UNIQUE !!

on => create isn’t a solution for your problem. This will only disable the validation rule for update operations.

Besides that, I think you’re using the validator in a wrong way. Your validation rule

array('fk_cuota_def_anual_id,tipo_cuota, mes_calendario', 'unique')

means, that each of the listed attributes should be unique. I think what you’re trying to acomplish is, that the whole triple should be unique, right? Maybe you can use the unique-multiple-columns-validate extension for this.

Yes, that’s what I wont!

I’ll read/study your extension !

Best Regards