Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Activerecord 仅在创建时验证唯一性-我键入的错误是什么?提供的例子_Activerecord_Phpactiverecord - Fatal编程技术网

Activerecord 仅在创建时验证唯一性-我键入的错误是什么?提供的例子

Activerecord 仅在创建时验证唯一性-我键入的错误是什么?提供的例子,activerecord,phpactiverecord,Activerecord,Phpactiverecord,我有以下代码: class Member extends ActiveRecord\Model { static $validates_uniqueness_of = array( array('name', 'message' => "That name has already been registered. Please choose another", 'on' => 'create'), array('email', 'message'

我有以下代码:

 class Member extends ActiveRecord\Model
  {
   static $validates_uniqueness_of = array(
      array('name', 'message' => "That name has already been registered. Please choose another", 'on' => 'create'),
      array('email', 'message' => "That email has already been registered. Please choose another", 'on' => 'create')
   );
  }
问题是当我更新时它会检查唯一性。我不想那样。只有当我创造的时候

我打错什么了?

试试类似的方法

validates_uniqueness_of :name, :on => :create
validates_uniqueness_of :email, :on => :create

这应该已经做到了,尝试一下=)

hmm,应该根据工作原理,但如果没有,最好的尝试可能是自定义验证函数,如该链接中所述:

  class User extends ActiveRecord\Model
  {
    public function validate() 
    {
      if ( your_uniqueness_check_here )
      {
        $this->errors->add('namecheck', "can't be the same as someone elses.");
      }
   }
 }

另一个选项是使用
save(false)
调用进行更新,因此跳过验证。也有点棘手。

谢谢,但我正在寻找使用PHPActiveRecord的示例。我的错是,没有看到标签,抱歉。