class Person extends CActiveRecord {
...
}
class Employee extends Person {
...
}
class ProjectManager extends Employee {
...
}
class Engineer extends Employee {
...
}
// example 1
$engineer = Engineer::model()->findByPk(1);
$engineer->name = 'Steve';
// example 2
if (isset($_POST['Engineer'])) {
$engineer = new Engineer();
// $_POST['Engineer'] may contain 'name' property inherited from Person class
$engineer->attributes = $_POST['Engineer'];
$engineer->save();
}
I cannot figure out any way to implement this with Yii ActiveRecord, any thoughts?
storing data for all classes in one table looks clumsy (especially in real application with wider hierarhy)
I know that I can access name property like this $engineer->person->name using BELONGS_TO relation, but $engineer->name and inheritance looks better
Was looking to do a similar thing. Thought about views, Single Table Inheritance and the like, but was worried about scalability and efficiency. I found this post which might be helpful, describing Class Table Inheritance as a database design. I haven’t implemented it yet, so I can’t say how well it works, but worth looking into.