Comparing
#4 with
#5
Content
[...]
{
if (!isset($attributes['type_id'])) { // When creating and $type_id has not defined yet
return parent::instantiate($attributes);
}
$classRecord = AnimalType::model()->findByPk($attributes['type_id']); // Load the "Type" class
if($classRecord === null)
throw new CException('Type not found');
$className = $classRecord->name; // Let's assume that name is the field storing the name of the class
$model = new $className(null); // Null param needed for populating the record
return $model;
}[...]