代码之家  ›  专栏  ›  技术社区  ›  Justin Giboney

我做的条令子类正确吗?为什么会出错?

  •  0
  • Justin Giboney  · 技术社区  · 15 年前

    这是我为订单上的行项目设计的模型

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

    这是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 回复  |  直到 15 年前
        1
  •  1
  •   Bob Gettys    15 年前

    另外,在子类setTableDefinition调用中,添加一个父类::setTableDefinition();顶部的声明。对setUp()方法也执行同样的操作。它可能会也可能不会解决你的问题,但这可能会在将来导致问题。至于你指的是什么,当我创建关系集合时,上次我使用列聚合继承时,它对我做了同样的事情……除非你直接查询,否则它可能根本不受支持。