1

次のような単一のIDを使用して一意を確認する方法を知っています。

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

次に、一意の2つの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 に答える