在教义中获取Table-instance的替代方法

时间:2010-09-06 13:04:44

标签: php symfony1 doctrine

在某些情况下Doctrine_Core::getTable('%Name%')会返回 Doctrine_Table个实例,而不是%Name%Table个实例。这显然是一个错误,但除了Doctrine_Core::getTable('%Name%')之外还有其他方法可以在教义中获取表格实例吗?

为了演示这种不正当的行为:这里是小问题的图式 跟踪系统

User:
  actAs: [Timestampable]
  tableName: issue_user
  columns:
    user_id:        { type: integer, primary: true, autoincrement: true }
    user_name:      { type: string(255) }
    user_role:      { type: enum, values: [worker, dispatcher, manager] }
    managed_by:     { type: integer }
    password:       { type: string(32) }
    salt:           { type: string(32) }
  relations:
    Manager:
      foreignAlias: Workers
      class: User
      local: managed_by
      foreign: user_id
      type: one
      foreignType: many

Issue:
  actAs: [Timestampable]
  columns:
    issue_id:        { type: integer, primary: true, autoincrement: true }
    from_ceh:        { type: string(255) }
    from_name:       { type: string(255) }
    from_phone:      { type: string(255) }
    from_location:   { type: string(255) }
    comp_name:       { type: string(255) }
    comp_serial:     { type: string(255) }
    comp_os:         { type: enum, values: [Win95, Win98, WinNT, WinME, Win2000, WinXP, Vista, Win7] }
    issue_title:     { type: string(255) }
    comment:         { type: string(255) }
    owner_id:        { type: integer }
    is_executed:     { type: bool }
  relations:
    Owner:
      onDelete: CASCADE
      foreignAlias: Issues
      class: User
      local: owner_id
      foreign: user_id
      type: one
      foreignType: many

当我致电Doctrine_Core::getTable('User')时,它会返回UserTable 实例,但如果我在这样的查询之后调用它:

Doctrine_Query::create()
        ->select('u.user_id, ws.user_id, i.*')
        ->from('User u, u.Workers ws, ws.Issues i')
        ->where('u.user_id=', $manager_id)
        ->fetchArray();

调用Doctrine_Core::getTable('User')会返回Doctrine_Table 实例

P.S。学说1.2.3

1 个答案:

答案 0 :(得分:0)

最新版本的doctrine 1.2(听起来你使用它支持XxxTable :: getInstance(),虽然它所做的只是调用Doctrine :: getTable('Xxx');