1

我知道如何使用单个 id 来检查唯一性,如下所示,

$addrules = array(
        'GradeName' =>  array('required','regex:/^./','unique:class,GradeName,'.$id.',AutoID'),   
                             );

然后我想用来检查唯一的两个 id(主键和外键)

这是我的代码:

$update = array(
        'GradeName' =>  array('required','regex:/^./','unique:class,GradeName,'.$schoolid.',schoolid,'.$data.',AutoID'),   
                             );

但我有以下错误:

SQLSTATE[42S22]: Column not found: 1054 Unknown column '20' in 'where clause' (SQL: select count(*) as aggregate from `class` where `GradeName` = g1 and `schoolid` <> 3 and `20` = AutoID)

我该如何解决这个问题?

4

2 回答 2

1

我已使用以下代码修复了此错误

$update = array(
        'GradeName' =>  array('required','regex:/^./','unique:class,GradeName,'.$data.',AutoID,schoolid,'.$schoolid),   
                             );
于 2015-02-17T10:47:30.180 回答
0

你传递了错误的参数,后面跟着 doc

unique:table,column,except,idColumn

You may also specify more conditions that will be added as "where" clauses to the query:

'email' => 'unique:users,email_address,NULL,id,account_id,1'
In the rule above, only rows with an account_id of 1 would be included in the unique check.

因此,您可以按自己的方式传递外键。

于 2015-02-17T10:00:27.260 回答