質問

DoctrineでPOSシステムの構築を開始しました。私は注文を受けていますが、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
役に立ちましたか?

解決

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

また、サブクラスのsetTableDefinition呼び出しで、parent :: setTableDefinition();を追加します。上部のステートメント。 setUp()メソッドでも同じことを行います。問題を解決する場合としない場合がありますが、将来問題が発生する可能性があります。あなたが言及していることに関しては、Doctrineがリレーションシップコレクションをハイドレイトするとき、前回カラム集約継承を使用したとき、それは私に同じことをしました...直接クエリしない限り、それは単にサポートされないかもしれません。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top