0

我有 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'),但我看不出有什么问题?

4

2 回答 2

2

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

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

由于您的班级名称是SurveyOption并且文件是SurveyOption.php

于 2012-06-15T17:57:40.860 回答
1

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

于 2012-06-15T16:10:05.537 回答