dpxo13079 2017-04-26 13:35
浏览 42
已采纳

如何在特定记录范围内使用is_unique表单验证?

I have a table called participants:

CREATE TABLE IF NOT EXISTS `participants` (
  `id` int(8) NOT NULL AUTO_INCREMENT,
  `email` varchar(30) NOT NULL,
  `name` varchar(40) NOT NULL,
  `birthdate` date NOT NULL,
  `personal_number` varchar(16) DEFAULT NULL,
  `phone` varchar(16) NOT NULL,
  `photo` varchar(100) NOT NULL,
  `address` text NOT NULL,
  `city_id` int(3) DEFAULT NULL,
  `tournament_id` int(8) NOT NULL,
  `time_created` datetime NOT NULL,
  `time_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `city_id` (`city_id`),
  KEY `tournament_id` (`tournament_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

The rule for creating participants is each registered email address can only participate in one tournament (foreign key tournament_id); therefore two records with the same email address but different tournament_id should be allowed.

Is is_unique form validation able to do this operation? Or should I create a callback or a helper?

  • 写回答

1条回答 默认 最新

  • dongyue5686 2017-04-26 13:42
    关注

    is_unique is just a short name for value_does_not_already_exists_in_a_single_column.

    So, no - it won't do the job; you'll need a callback.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 R运行没有名称为"species"的插槽对于此对象类"SDMmodelCV"
  • ¥20 基于决策树的数字信号处理,2ask 2psk 2fsk的代码,检查下报错的原因
  • ¥20 python作业求过程
  • ¥15 wincc已组态的变量过多
  • ¥60 如图:直线与椭圆X轴平行,求直线与椭圆任意一点的相切坐标计算公式
  • ¥50 如何用python使用opencv里的cv::cudacodec::VideoWriter函数对视频进行GPU硬编码
  • ¥100 c#solidworks 二次开发 工程图自动标边线法兰 等折弯尺寸怎么标
  • ¥15 halcon DrawRegion 提示错误
  • ¥15 FastAPI Uvicorn启动显示404
  • ¥15 centos7.9脚本,怎么排除特定的访问记录