I am having problems using an abstract class that inherits from CActiveRecord. I am creating a work management section of my website to track different work done on different incidents. I created a generic "Worklog" class that is abstract and extends CActiveRecord. I then created several other class that extend the Worklog class to add custom functionality for those various classes.
The classes work great and have no problems when I create new records, but I have problems when I call any of extendedClass::model()->find() methods. The methods always return the following error:
"Fatal error: Cannot instantiate abstract class Worklog in /***/db/ar/CActiveRecord.php on line 378"
It seems as though it is does not recognize that I am using the extended class and not the abstract class, although it can differentiate when I am saving records just not finding.
Have a good look at CActiveRecord::model() method. It takes CLASS as a default value which is always "CActiveRecord" even for children. So for your inherited classes you have to override model() like this (generated by Gii):
public static function model($className=__CLASS__)
{
return parent::model($className);
}
Or call CActiveRecord::model($extendedClassName)->find() which is less convenient.