0

CrudeCode.php の 69 ~ 70 行をコメントアウトし、Gii を使用して、主キーとして 2 つの複合キーを持つモデルを作成しました。ページを参照すると、エラーが発生します

2012/09/19 09:50:29 [error] [exception.CException] exception 'CException' with message 'Property "ComAsset.Array" is not defined.' in /opt/dam/yii-1.1.12.b600af/framework/base/CComponent.php:131
Stack trace:
#0 /opt/dam/yii-1.1.12.b600af/framework/db/ar/CActiveRecord.php(144): CComponent->__get('Array')
#1 /opt/dam/protected/views/comAsset/_view.php(9): CActiveRecord->__get('Array')
#2 /opt/dam/yii-1.1.12.b600af/framework/web/CBaseController.php(131): require('/opt/dam/protec...')
#3 /opt/dam/yii-1.1.12.b600af/framework/web/CBaseController.php(96): CBaseController->renderInternal('/opt/dam/protec...', Array, false)
#4 /opt/dam/yii-1.1.12.b600af/framework/zii/widgets/CListView.php(260): CBaseController->renderFile('/opt/dam/protec...', Array)
#5 /opt/dam/yii-1.1.12.b600af/framework/zii/widgets/CBaseListView.php(161): CListView->renderItems()
#6 [internal function]: CBaseListView->renderSection(Array)
#7 /opt/dam/yii-1.1.12.b600af/framework/zii/widgets/CBaseListView.php(144): preg_replace_callback('/{(\w+)}/', Array, '{summary}?{sort...')
#8 /opt/dam/yii-1.1.12.b600af/framework/zii/widgets/CBaseListView.php(129): CBaseListView->renderContent()
#9 /opt/dam/yii-1.1.12.b600af/framework/web/CBaseController.php(174): CBaseListView->run()
#10 /opt/dam/protected/views/comAsset/index.php(20): CBaseController->widget('zii.widgets.CLi...', Array)
#11 /opt/dam/yii-1.1.12.b600af/framework/web/CBaseController.php(127): require('/opt/dam/protec...')
#12 /opt/dam/yii-1.1.12.b600af/framework/web/CBaseController.php(96): CBaseController->renderInternal('/opt/dam/protec...', Array, true)
#13 /opt/dam/yii-1.1.12.b600af/framework/web/CController.php(870): CBaseController->renderFile('/opt/dam/protec...', Array, true)
#14 /opt/dam/yii-1.1.12.b600af/framework/web/CController.php(783): CController->renderPartial('index', Array, true)
#15 /opt/dam/protected/controllers/ComAssetController.php(128): CController->render('index', Array)
#16 /opt/dam/yii-1.1.12.b600af/framework/web/actions/CInlineAction.php(50): ComAssetController->actionIndex()
#17 /opt/dam/yii-1.1.12.b600af/framework/web/CController.php(309): CInlineAction->runWithParams(Array)
#18 /opt/dam/yii-1.1.12.b600af/framework/web/filters/CFilterChain.php(134): CController->runAction(Object(CInlineAction))
#19 /opt/dam/yii-1.1.12.b600af/framework/web/filters/CFilter.php(41): CFilterChain->run()
#20 /opt/dam/yii-1.1.12.b600af/framework/web/CController.php(1146): CFilter->filter(Object(CFilterChain))
#21 /opt/dam/yii-1.1.12.b600af/framework/web/filters/CInlineFilter.php(59): CController->filterAccessControl(Object(CFilterChain))
#22 /opt/dam/yii-1.1.12.b600af/framework/web/filters/CFilterChain.php(131): CInlineFilter->filter(Object(CFilterChain))
#23 /opt/dam/yii-1.1.12.b600af/framework/web/CController.php(292): CFilterChain->run()
#24 /opt/dam/yii-1.1.12.b600af/framework/web/CController.php(266): CController->runActionWithFilters(Object(CInlineAction), Array)
#25 /opt/dam/yii-1.1.12.b600af/framework/web/CWebApplication.php(283): CController->run('')
#26 /opt/dam/yii-1.1.12.b600af/framework/web/CWebApplication.php(142): CWebApplication->runController('comAsset')
#27 /opt/dam/yii-1.1.12.b600af/framework/base/CApplication.php(162): CWebApplication->processRequest()
#28 /opt/dam/index.php(13): CApplication->run()
#29 {main}
REQUEST_URI=/dam/index.php?r=comAsset

yii フォーラムをググって調べましたが、yii 1.1.12 で複合キーを実装する方法に関する明確なドキュメントが見つかりません。誰でも詳しく説明できますか。

私のモデルでは、主キー関数を含めました

public function primaryKey()
{
    //return 'id';
    // For composite primary key, return an array like the following
    return array('fixed_asset', 'component');
}

/**
     * @return array relational rules.
     */
    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(
            'fixedAsset0' => array(self::BELONGS_TO, 'FixedAsset', 'fixed_asset'),
            'component0' => array(self::BELONGS_TO, 'Components', 'component_id'),
        );
    }

fixed_asset テーブルでは、主キーはfixed_assetcomponentです。component_idcomponents テーブルとfixed_asset_idfixed_asset テーブルの外部キーでもあります。私の関係と主キーは正しいですか?

4

0 に答える 0