【发布时间】:2011-03-26 21:17:21
【问题描述】:
我正在尝试使用 Doctrine 优化 symfony 应用程序。我偶然发现了以下问题:
在视图中我使用了 $project->getProgress();但是通过这样做,随着项目的增加,查询的数量也会增加。因此,我尝试使用左连接将进度放入项目查询(覆盖 findAll 方法),但这没有成功。查询的数量实际上增加了。
public function findAll($hydrationMode = null)
{
$q = $this->createQuery('p')
->leftJoin('p.progress pr')
->leftJoin('pr.sfGuardUser u')
->leftJoin('p.raws r')
->leftJoin('p.series');
return $q->execute(array(), $hydrationMode);
}
这是我试图用尽可能少的查询创建的结果:
array() {
[0]=>
array() {
["id"]=> string(1) "1"
...
["progress"]=>
array() {
array() {
array() { progress1 }
array() { progress2 }
array() { progress3 }
....
}
}
}
我查看了 symfony 和 Doctrine 的文档,但找不到我的答案。我也在谷歌上搜索了一段时间。 (几个月来我一直在寻找解决方案)我希望我已经足够好地描述了我的问题。
schema.yml:
projects:
actAs:
Timestampable: ~
columns:
user_id: integer(4)
series_id: bigint
pages: int
chapter: string
translators_id: bigint
proofreaders_id: bigint
cleaners_id: bigint
typesetters_id: bigint
raws_id: bigint
hide_project: bool
complete: bool
relations:
sfGuardUser:
local: user_id
foreign: id
onDelete: CASCADE
series:
local: series_id
foreign: id
type: one
foreignType: many
onDelete: CASCADE
progress:
local: id
foreign: projects_id
onDelete: CASCADE
type: one
foreignType: many
projectsProgress:
actAs: [Timestampable]
columns:
projects_id: bigint
user_id: integer(4)
job:
type: enum
notnull: true
values: [tl,pr,cl,ts]
beginpage: int
endpage: int
complete: bool
file: string
url: clob
relations:
sfGuardUser:
local: user_id
foreign: id
onDelete: CASCADE
projects:
local: projects_id
foreign: id
onDelete: CASCADE
foreignAlias: progress
【问题讨论】: