原则继承:在 WHERE 子句中使用父表列获取子表的行数



我正在处理一个具有多个订阅者(user_id)的系统,该系统具有多个客户和供应商(继承'Person'类)。我需要显示客户的数量&每个订阅者的供应商(子表的组总数)。如何使用DQL获得这些组的总数?

Person:
  columns:
    user_id: { type: integer }
    name:    { type: string(80) }
    //...
Customer:
  inheritance:
    type:     concrete
    extends:  Person
  columns:
    //...
Vendor:
  inheritance:
    type:     concrete
    extends:  Person
  columns:
    vendor_type:    { type: string(80), notnull: true }
    terms_id:       { type: integer }
    //...

看着我自己的问题,我意识到这是多么愚蠢。查询非常简单:

    $result =  Doctrine_Query::create()
        ->select('type, COUNT(*) AS count')
        ->from('Person')
        ->groupBy('type')
        ->fetchArray();

最新更新