CREATE TABLE `npctype` (
`Id` int(11) NOT NULL,
`Title` text,
PRIMARY KEY (`Id`),
KEY `type_title` (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `npcdescription` (
`Id` int(11) NOT NULL,
`TypeId` int(11) NOT NULL,
`Title` text,
...
PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Существуют модели npc* и npctype. В npc мне нужно подгрузить npctype(Title
) за счет npcdescription(TypeId
)
npcdescription(TypeId
) = npctype(Id
)
Как я понял, в модели npc нужно использовать relations HAS_ONE.
public function relations()
{
return array(
'npc_type_title'=>array(self::HAS_ONE, 'npctype', 'type_title'),
);
}
Контроллер ncp:
public function actionView($id)
{
$models = npc::model()->with('npc_type_title')->findAll();
$list = CHtml::listData($models, 'Id', 'Title');
print_r($list);
}
После чего вылезает эксепшн:
CDbException
Description
The relation "npc_type_title" in active record class "npc" is specified with an invalid foreign key "type_title". There is no such column in the table "npctype".
Source File
Z:\***\framework\db\ar\CActiveFinder.php(998)
Прошу помощи в связке\подгрузке данных
*модель npc сокращена от npcdescription