sfValidatorDoctrineUnique fails on capital letters

百般思念 提交于 2019-12-25 03:59:14

问题


I've setup a post validator in my symfony form to stop duplication of primary keys.

A primary key is a two-character string in this instance. Code used to validate:

$this->mergePostValidator(new sfValidatorDoctrineUnique(array(
  'model' => 'Manufacturers',
  'column' => 'id',
  'primary_key' => 'id'
)));

The primary key is uppercase (for example AU). Bizarrely the post validator triggers successfully is lowercase 'au' is entered into the field (i.e. stops it from going to the database and triggering a 500 integrity constraint error), but if entered correctly as 'AU' it doesn't seem to notice the duplication.

Any thoughts?


回答1:


That's not a symfony sfDoctrineValidator issue. All this validor does is to search your database for an existing record. If you are using a "_ci" (case-insensitive) collation (are you using mysql?) the search returns nothing - the validator is fooled.

Then when you insert the duplicate, you get a exception from the database. Try to change the collation of your table like this:

ALTER TABLE  `table` DEFAULT CHARACTER SET utf8 COLLATE utf8_bin

(you should tell doctrine to do it for you:

MyTable:
  options: { collate: utf8_bin, charset: utf8 }

)



来源:https://stackoverflow.com/questions/8024092/sfvalidatordoctrineunique-fails-on-capital-letters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!