私の目標は、ユーザー名と姓を使って、また、Recrutation YearとSemesterを介してドキュメントを検索することです。 文書は宣言のみに関連しています。つまり、文書が実際に1つの宣言と宣言に接続されています。Yiiフレームワーク - 同じ "through"テーブルを介した2つの関係
宣言はOutgoingStudentおよびRecrutationに関連しています。
したがって、ドキュメントを照会するときに、Declarationテーブルを使用してOutgoingStudentとRecrutationsも照会します。
ドキュメント内の関係のための私のコード:
return array(
'declaration' => array(self::BELONGS_TO, 'Declaration', 'DeclarationID'),
'outgoingStudentUserIdUser' => array(self::HAS_ONE, 'OutgoingStudent', 'OutgoingStudent_User_idUser','through'=>'declaration',),
'Recrutation' => array(self::HAS_ONE, 'Recrutation', 'Recrutation_RecrutationID','through'=>'declaration'),
);
そして今、私は、クエリを作りたい検索()関数の中で - >
'declaration','outgoingStudentUserIdUser' and 'Recrutation':
$criteria->with = array('declaration','Recrutation','outgoingStudentUserIdUser');
で、私はこのエラーを取得しています:
CDbCommand nie zdołał wykonać instrukcji SQL: SQLSTATE[42000] [1066] Not unique table/alias: 'declaration'. The SQL statement executed was: SELECT COUNT(DISTINCT
t
.DeclarationID
) FROMDocuments
t
LEFT OUTER JOINDeclarations
declaration
ON (t
.DeclarationID
=declaration
.idDeclarations
) LEFT OUTER JOINRecrutation
Recrutation
ON (declaration
.Recrutation_RecrutationID
=Recrutation
.RecrutationID
) LEFT OUTER JOINDeclarations
declaration
ON (t
.DeclarationID
=declaration
.idDeclarations
) LEFT OUTER JOINOutgoingStudent
outgoingStudentUserIdUser
ON (declaration
.OutgoingStudent_User_idUser
=outgoingStudentUserIdUser
.User_idUser
)
$criteria->with = array('declaration','Recrutation')
または$criteria->with = array('declaration','outgoingStudentUserIdUser')
のみを使用する場合は、bその他
おそらくそれは他の方法で行う必要がありますが、どうすればよいですか?
感謝を!私が達成しようとしていた目標は、CGridViewのRecrutationsデータとOutgoing Studentsデータ(名前と姓)を検索して、ドキュメントを表示することでした(例えば、CGridViewでshowを実行すると、recrutation id 1に属し、ジョンスミス)。 search()で "with"を使用するというアイデアは私のものではありませんでした - 私はここでそれを見つけました:http://www.yiiframework.com/wiki/281/searching-and-sorting-by-related-model-in-cgridview/ – Pax0r
ああなるほど!はい、それについての私のせいでした。今、あなたは私の提案を試しましたか?それは動作しましたか? –
私は手作業でSQLを書いてきましたが、まだあなたのヒントを一般的に使っていますので、私はあなたの答えを受け入れています – Pax0r