具有繼承自A的類A和類B以及分別具有比率1:M(A,C)的類C(創建B類的對象,並試圖訪問形式$ B-> C-> attributeOfC「與消息」拋出Doctrine_Record_UnknownPropertyException未知記錄屬性/相關分量Doctrine 1.2 ORM繼承了類對其父關係的訪問
在代碼的簡單示例:
//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();