【发布时间】:2011-07-01 23:56:51
【问题描述】:
这是我实际拥有的架构的摘录
Software:
columns:
title:
type: string(255)
id_publisher:
type: integer
id_developper:
type: integer
Company:
columns:
name:
type: string(255)
nationality:
type: string(255)
如您所见,我的软件模型有两个外部引用:发布者和开发者。我希望为这两个引用中的每一个创建一个一对多的关系。问题是他们都是公司。
我首先在我的软件模型上尝试了如下所示的操作,但该关系仅适用于第一个本地引用 id_publisher。
relations:
Company:
type: one
foreignType: many
local: [id_publisher, id_developper]
foreign: id
然后我尝试了(总是在软件模型上):
relations:
Publisher:
class: Company
type: one
foreignType: many
local: id_publisher
foreign: id
Developper:
class: Company
type: one
foreignType: many
local: id_developper
foreign: id
但是当我执行一个计算软链接到公司数量的查询时......
public function findAllQuery(Doctrine_Query $q = null) {
$q = Doctrine_Query::create()
->select('c.*, COUNT(s.id) AS count_software')
->from('Company c')
->leftJoin('c.Software s')
->groupBy('c.id');
return $q;
}
...在 COUNT 子句中只考虑发布者。
最后,我的问题是,如何处理同一模型的多个一对多关系? 感谢您的宝贵时间!
【问题讨论】:
标签: php doctrine one-to-many