Hi,
I am implementing a Activity / update stream for a social networking site. I need to define relations at runtime based on the ‘activityType’ field value. For instance if its value is “photoalbum” it should relate to a photoalbum model or if its value is “Event” then it should relate to the event model.
I tried to do it like this:
public function relations()
{
$relations = array();
if(!$this->isNewRecord)
{
$relations = array(
'user' => array(self::BELONGS_TO, 'User', 'userId'),
'parent' => array(self::BELONGS_TO, $this->parentType, 'parentId'),
);
}
// print_r($relations);
// die();
return $relations;
}
But, I get an error that the property Activity.parentType is not defined. Any idea how to fix this. I know we can define relation separately for every model. But this looks more cleaner and reduces redundancy.
Thnx