Hi all,
I’m having trouble trying to get a particular relation to work with my CActiveRecord model called User. I want to express the following as a relation in the model:
public function relations()
{
return array(
'userDetails' => array(self::HAS_MANY, 'UserDetail', '', 'with' => array('detail' => array('on' => '`userDetails`.`UserID` = :userId')), 'params' => array(':userId' => $this->ID)),
);
}
Unfortunately this doesn’t work at all when I try to lazy load userDetails:
$newUser = User::model()->findByPk(32502);
Yii::trace($newUser->ID);
$newUser->userDetails;
This throws an error Property “User.ID” is not defined. It doesn’t make any sense since The trace actually returns back 32502. What am I doing wrong or is this some kind of bug with Yii?
Thanks