Yii,当使用 with() 方法调用时,findAll 中的错误


Yii, Error in findAll, when called using with() method.

>我有PHP类

class SurveyQuestion extends CActiveRecord
{
    public function relations()
    {
    // NOTE: you may need to adjust the relation name and the related
    // class name for the relations automatically generated below.
    return array(
        'surveyOptions' => array(self::HAS_MANY, 'SurveyOptions', 'surveyQuestion_id'),
        'survey' => array(self::BELONGS_TO, 'Survey', 'survey_id'),
         );
    }
}

在控制器中,我想获取带有其选项的调查列表,所以我正在做..

$this->renderJson(array('success'=>true, 'message'=>'Records Retrieved Successfully',
'data'=>SurveyQuestion::model()->with('surveyOptions')->findAll()));

但是当调用此控制器方法时,我收到此错误。

include(SurveyOptions.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory

根据 http://www.yiiframework.com/doc/guide/1.1/en/database.arr,我应该能够在每个调查中获得选项的回复。

我认为,inclue(SurveyOptions.php)应该是SurveyOption.php(没有's'),但是我看不出出了什么问题?

阅读您的评论后,您只需要更改您的关系:

'surveyOptions' => array(self::HAS_MANY, 'SurveyOption', 'surveyQuestion_id')

由于您的类名是SurveyOption,文件是调查选项.php

SurveyQuestion::model()->with('surveyOptions')->findAll()中使用与 SurveyOptions 中定义的名称的关系