1
我有这样的学说结构。学说2:没有水合计数实体的相关实体
/**
* @ORM\Entity
* @ORM\Table(name="entity_deviceProfile")
*/
class DeviceProfile
{
/**
* @ORM\ManyToMany(targetEntity="TranscodeProfile", inversedBy="deviceProfiles")
* @ORM\JoinTable(name="entity_deviceProfile_rel_transcodeProfiles_transcodeProfile")
* @var \Doctrine\Common\Collections\Collection
*/
protected $transcodeProfiles = null;
}
我希望有方法getTranscodeProfileCount()
在DeviceProfile
类。
所以我添加的功能,以DeviceProfile
:
public function getTranscodeProfilesCount() {
if (!$this->transcodeProfiles->isInitialized()) {
$this->transcodeProfiles->initialize();
}
return $this->transcodeProfiles->count();
}
它工作正常,除了内存的使用情况和性能。保湿整个收藏需要大量的记忆和时间。我有成千上万的transcodeProfiles
,这个数字还在增长。
有没有办法在不保湿收藏的情况下获得记录数? PS:我知道我可以通过运行count()
查询$em
从实体以外做到这一点。但不幸的是,这个功能是巨大的应用程序的一部分,更新所有的函数调用是一项巨大的工作。所以我正在寻找解决现有功能问题的方法。