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

Php 我做的条令子类正确吗?为什么会出错?,php,mysql,doctrine,subclass,Php,Mysql,Doctrine,Subclass,我开始在理论上建立POS系统。我得到了一个命令,但我不知道我是否以正确的方式为教义建立了子类 这是我为订单上的行项目设计的模型 lineItem: line_total, order_id, type rentLineItem: returned_date_time, item_id, sold buyLineItem: item_id 数据库看起来是这样的。类型为1(租金)或2(购买) 这是lineItem类 class lineItem extends Doctrine_Record {

我开始在理论上建立POS系统。我得到了一个命令,但我不知道我是否以正确的方式为教义建立了子类

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

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看起来类似)

这是我调用对象的代码

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

。。。它消除了这个错误,但是当我在代码中调用类来获取行项目时,它不会将其识别为rentLineItem或buyLineItem,就像LineItem一样,我想doctrine不支持我想要的关系类型。
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