如何向Doctrine_Record类添加描述

时间:2014-02-25 00:38:25

标签: doctrine symfony-1.4

我在下面的方案中描述了一个表CustBillingEmployee

CustBillingEmployee:
  connection: doctrine
  tableName: cust_billing_employee
  columns:
    employee_num:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: true
      autoincrement: false
    job_title_code:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    cost:
      type: 'decimal(5, 2)'
      fixed: false
      unsigned: false
      primary: false
      default: '0.00'
      notnull: true
      autoincrement: false
  relations:
    HsHrEmployee:
      local: employee_num
      foreign: emp_number
      type: one

以及下面的课程

class cust_billing_employee extends Doctrine_Record
{
    public function setTableDefinition()
    {
        $this->hasColumn('employee_num', 'integer',4,array(
         'type' => 'integer',
         'length' => 4,
         'fixed' => false,
         'unsigned' => false,
         'primary' => true,
         'autoincrement' => false,
         ));
        $this->hasColumn('job_title_code', 'integer',4,array(
         'type' => 'integer',
         'length' => 4,
         'fixed' => false,
         'unsigned' => false,
         'primary' => false,
         'notnull' => true,
         'autoincrement' => false,
         ));
        $this->hasColumn('cost', 'decimal',5,array(
            'fixed' => false,
            'unsigned' => false,
            'primary' => false,
            'default' => '0.00',
            'notnull' => true,
            'autoincrement' => false,
        ));
    }

    public function setUp()
    {
        $this->hasOne('User', array(
            'local' => 'employee_num',
            'foreign' => 'emp_number'
        ));
    }

    public function __toString() {
       return "HI";
    }
}

当我尝试像这样提取特定对象时:

echo Doctrine::getTable('CustBillingEmployee')->find(1);

我收到错误

No description for object of class "CustBillingEmployee"

我希望函数__toString()从父类重写,但事实并非如此。我该如何向对象添加描述呢?

当显示每条记录时,我希望能够显示员工姓名,而不仅仅是employee_num密钥和职位名称,而不是job_title_cost

1 个答案:

答案 0 :(得分:0)

你可以发布整个调用堆栈,什么代码会抛出该错误?

对我来说可疑的是,cust_billing_employee类的名称不是CustBillingEmployee而不是BaseCustBillingEmployee,这将是Symfony 1.4的默认行为。你是否“手工”编写了这段代码?

由于您的架构是在schema.yml中定义的,因此您应该使用./symfony doctrine:build-model任务。

这应该生成正确的类:CustBillingEmployee扩展BaseCustBillingEmployee,扩展sfDoctrineRecord,然后Doctrine_Core::getTable('CustBillingEmployee')->find(1)应该完美。

另请注意,您不应触及BaseCustBillingEmployee,因为这是自动生成的代码,所有修改(如__toString)都应在CustBillingEmployee类中完成。