2009-08-04 2 views
0

나는 Doctrine에서 POS 시스템을 만들기 시작했습니다. 주문을 받고 있지만 Doctrine을위한 적절한 방법으로 하위 클래스를 설정했는지 여부에 대한 단서가 없습니다. 여기 Doctrine 서브 클래스를 올바르게하고 있습니까? 왜 오류입니까?

내가 주문 데이터베이스가 보이는

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

에 광고 항목과 함께 제공되는 모델입니다. 유형

여기
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')); 
} 
} 

는 것입니다 (buyLineItem이 비슷) 1 (임대) 또는 2 (구매) 여기

여기
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 클래스입니다 광고 항목이 클래스를입니다 중 하나입니다 코드 객체를 호출했습니다.

$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으로 인식하지 못합니다 (lineItem –

+0

). 위를 참조하십시오 ... 더 도움이되지 못해 미안 해요 ... –

+0

doctrine은 내가 원하는 관계 유형을 지원하지 않는다고 생각합니다. –

관련 문제