Hey,
just started using relational AR.
However it is not working:
I get the following error:
Property "user.cc" is not defined.
The Property is defined in country.cc and not in user.cc
Here is the User-Controller Snippet
public function actionView($id)
{
$myModel = $this->loadModel($id);
$test = $myModel->countryUser;
print $test;
$this->render('view',array(
'model'=>$myModel,
));
}
Here is the User-Model Snippet
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(
// choose ModelName KeyName
'countryUser' => array(self::BELONGS_TO, 'country', 'cc'),
);
}
And here the relevant DB Table Definitions
CREATE TABLE IF NOT EXISTS `dfg`.`tb_user` (
`idUser` INT NOT NULL AUTO_INCREMENT ,
`username` VARCHAR(45) NOT NULL ,
`country` VARCHAR(45) NULL ,
`state` VARCHAR(45) NULL ,
PRIMARY KEY (`idUser`) ,
INDEX `countryUser` (`country` ASC) ,
CONSTRAINT `countryUser`
FOREIGN KEY (`country` )
REFERENCES `dfg`.`tb_geo_country` (`cc` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS `dfg`.`tb_geo_country` (
`cc` VARCHAR(2) NOT NULL ,
`country` TEXT NULL ,
PRIMARY KEY (`cc`) )
ENGINE = InnoDB;