Issue
I want add aditional methods in CActiveRecord, but if class Project_Model extends CActiveRecord {}
get error
The table "Project_ActiveRecord" for active record class "Project_ActiveRecord" cannot be found in the database.
I want create simple structure: CActiveRecord->Project_ActiveRecord (only extend methods)->Table (real table).
How can do this?
Solution
The error is clear: You don't have a table named Project_ActiveRecord
in your DB!
If Project_Model
is going to be the base model for your others active record models then you should do something like:
//A base classe example that has a behavior shared by all the inherited class
abstract class Project_Model extends CActiveRecord
{
public function behaviors(){
return array(
'CTimestampBehavior' => array(
'class' => 'zii.behaviors.CTimestampBehavior',
'setUpdateOnCreate' => true
),
);
}
}
And then you can declare the other class that will have a table in the db:
class YourClass extends Project_Model
{
/**
* Returns the static model of the specified AR class.
* @param string $className active record class name.
* @return Token the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'YourClassTable';
}
...
}
Then you shoudl never call the class Project_Model
(this is why I put the keyword abstract
) in your code, you have to call the inherited classes that have an existing table in the db!
Answered By - darkheir
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.