当创建类 B 的对象并尝试访问表单 $B-> C->attributeOfC 抛出 Doctrine_Record_UnknownPropertyException 'with message' 未知记录属性/相关组件
代码中的一个简单示例:
//A
class tableA extends Doctrine_Record{
public function setTableDefinition() {
$this->hasColumn('tableA_id', 'integer', null, array(
'primary' => true, 'autoincrement' => true));
$this->hasColumn('tableC_id','integer');
$this->setSubclasses(array(
'tableB' => array('type' => 1)
)); }
function setup() {
$this->setTableName("tableA");
$this->hasOne('tableC', array(
'local' => 'tableC_id',
'foreign' => 'tableC_id'
)); }
}
//B
class tableB extends tableA{
public function setTableDefinition() {
$this->hasColumn('tableB_id', 'integer', null, array(
'primary' => true, 'autoincrement' => true));
$this->hasColumn('tableA_id','integer');
}
function setup() {
$this->setTableName("tableB");
}
}
//C
class tableC extends Doctrine_Record{
public function setTableDefinition() {
$this->hasColumn('tableC_id', 'integer', null, array(
'primary' => true, 'autoincrement' => true));
$this->hasColumn('attributeOfC','string');
}
function setup() {
$this->setTableName("tableC");
$this->hasMany('tableA as Alias', array(
'local' => 'tableC_id',
'foreign' => 'tableC_id'
)); }
}
//some code where we create $objectOfCClass as an instance of tableCe
$objectA = new $tableA();
$objectA->tableC=$objectOfCClass;
$objectA->save();