2009-08-04 13 views
0

私はDoctrineでPOSシステムを構築し始めました。私は命令を受けていますが、Doctrineのために適切な方法でサブクラスを設定するかどうかは分かりません。ここでDoctrineサブクラスを正しく使っていますか?なぜエラー?

は、私は、データベースがそのように見えるため

lineItem: line_total, order_id, type 
rentLineItem: returned_date_time, item_id, sold 
buyLineItem: item_id 

上のラインアイテムに思い付いたモデルです。タイプのいずれかである1(家賃)または2(買い)

は、ここでのLineItemクラス

class lineItem extends Doctrine_Record 
{ 
    public function setTableDefinition() 
    { 
    $this->hasColumn('line_total','int'); 
    $this->hasColumn('order_id','int'); 

    $this->setSubclasses(array(
     'rentLineItem' => array('type' => 1), 
     'buyLineItem' => array('type' => 2), 
    ) 
    ); 
    } 

    public function setUp() 
    { 
    $this->hasOne('order', array('local' => 'order_id', 'foreign' => 'id')); 
    } 
} 

はここでここでrentLineItemクラス(buyLineItemが似ています)

class rentLineItem extends lineItem 
{ 
    public function setTableDefinition() 
    { 
    $this->hasColumn('returned_date_time','datetime'); 
    $this->hasColumn('sold','tinyint', 2); // just in case it is sold at the end of the rental 
    $this->hasColumn('item_id','int'); 
    } 

    public function setUp() 
    { 
    $this->hasOne('item', array('local' => 'item_id', 'foreign' => 'id')); 
} 
} 

があるされています私はここで

$q = Doctrine_Query::create() 
->select('*') 
->from('order') 
->where('DATE(creation_date_time) = \'' . $theDate . '\''); 

$orders = $q->execute(); 

$totalRents = 0; 
$totalSales = 0; 

foreach ($orders as $order) { 
    foreach ($order->line_items as $lineItem) { 
    if ($lineItem->type == 1) { 
     $totalRents++; 
    } else if ($lineItem->type == 2) { 
     $totalSales++; 
    } 
    } 
} 

オブジェクトを呼び出しているコードは、私が取得していますエラーです

Fatal error: Uncaught exception 'Doctrine_Record_UnknownPropertyException' with message 'Unknown record property/related component "type" on "lineItem"' in 
/Developer/Projects/VEL/lib/vendor/doctrine/Doctrine/Record/Filter/Standard.php:55 Stack trace: #0 
/Developer/Projects/VEL/lib/vendor/doctrine/Doctrine/Record.php(1296): Doctrine_Record_Filter_Standard->filterGet(Object(lLineItem), 'type') #1 
/Developer/Projects/VEL/lib/vendor/doctrine/Doctrine/Record.php(1255): Doctrine_Record->_get('type', true) #2 
/Developer/Projects/VEL/lib/vendor/doctrine/Doctrine/Access.php(72): Doctrine_Record->get('type') #3 
/Developer/Projects/VEL/manage/manage/dailyincomeexpensereport.php(29): Doctrine_Access->__get('type') #4 {main} thrown in 
/Developer/Projects/VEL/lib/vendor/doctrine/Doctrine/Record/Filter/Standard.php on line 55 

答えて

1

$ this-> hasColumn( 'type'、 'int');を追加します。あなたのサブクラス呼び出しの上に。サブクラス化に使用する前に列を宣言する必要があります。

また、サブクラスのsetTableDefinition呼び出しで、parent :: setTableDefinition();を追加します。声明の上部にあるステートメント。また、setUp()メソッドでも同じことをします。それはあなたの問題を解決するかもしれないし、解決しないかもしれないが、それは将来問題を引き起こすかもしれない。あなたが何を参照しているのかというと、Doctrineが関係コレクションを水和させるとき、最後に列集約継承を使用したときにも同じことが起こりました...直接照会しない限り、単にサポートされないことがあります。

+0

私はそのエラーを取り除いていますが、コード内のクラスを呼び出してラインアイテムを取得すると、それはrentLineItemまたはbuyLineItemとして認識されません。ちょうどラインアイテム –

+0

上記を参照してください...私はもっと助けることはできません申し訳ありません... –

+0

私はdoctrineは私が望む関係の種類をサポートしていないと思います。 –

関連する問題