我的目标是有可能通过用户姓名和姓氏以及招聘年份和学期来搜索文档。文档仅与声明相关,文档与一个声明相关联,而声明可以与一个或无文档相关联。
声明与 OutgoingStudent 和 Recrucation 有关。
因此,当查询文档时,我还想通过声明表查询 OutgoingStudent 和 Recruations。
我在文档中的关系代码:
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'),
);
现在在 search() 函数中,我想查询 -> with
'declaration','outgoingStudentUserIdUser' and 'Recrutation':
$criteria->with = array('declaration','Recrutation','outgoingStudentUserIdUser');
我收到此错误:
CDbCommand nie zdołał wykonać instrukcji SQL:SQLSTATE[42000] [1066] 不是唯一的表/别名:“声明”。执行的 SQL 语句为: 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')
仅使用两者时都没有错误。
所以可能应该以其他方式完成,但是如何?