English 中文(简体)
把所有记录都填满了两次
原标题:Doctrine loads all records twice

我有一个名为“强”的实体,名称为“强”类别(/强),包括以下领域:

id: integer
name: string
slug: string
children: OneToMany(targetEntity="Category", mappedBy="parent")
parent: ManyToOne(targetEntity="Category", inversedBy="children")

如你所见,每一类人可以是另一类人的子女的父母。

我需要将所有类别都映射成一个阵列 所以我想最好把它们一起装上

$categoryRepository->findAll();

稍后,在绘图方法上, 我想得到每个类别的孩子, 所以我使用

$category->getChildren();

我假设,既然我首先装入了这些类别,只有1个查询将被执行,但配置文件显示不同!那里有 is 1个查询,它从中获取记录 all (配置文件的产出):

SELECT t0.id AS id1, t0.name AS name2, t0.slug AS slug3, t0.parent_id AS parent_id4
FROM acme_category t0

然后还有另一个查询 : < 坚固> 每一个 < / 坚固 > 的记录 :

SELECT t0.id AS id1, t0.name AS name2, t0.slug AS slug3, t0.parent_id AS parent_id4
FROM omnt_work_category t0 WHERE t0.parent_id = 1

SELECT t0.id AS id1, t0.name AS name2, t0.slug AS slug3, t0.parent_id AS parent_id4
FROM omnt_work_category t0 WHERE t0.parent_id = 1

etc..

为什么呢 我怎么能让它从一开始就装满所有记录呢

谢谢!

最佳回答

您可以通过在关系注释上声明 ficker=“EAGER” 自动装入 。

无论如何看您的执行, 它看起来像您试图通过维持一个儿童/ 父母关系来建立数据等级。 您也许最好为此执行一个嵌套套式解决方案。 有一些用于“ 理论2” 的图书馆可以帮你解决这个问题 。

我曾经使用过并建议过的其中一个是 & gt; & gt; ; < a href="https://github.com/blt04/doctrin2- nestesteset" rel=“ nofollow” >https://gitub.com/blt04/doctrine2-nestedset

当然令人感兴趣的是,“理论”试图多次重复记录而不是搜索“缓存 ” 。 也许它处理关系项目的缓存略有不同。 这当然值得调查。

问题回答

暂无回答




相关问题
POCO objects with lazy loading

I am new to ASP.NET MVC, IoC, POCO, etc. So I want to know is it OK to use such kind of architecture. This is my demo project. Project.Core (this assembly referenced by all project) public class ...

CGImage/UIImage lazily loading on UI thread causes stutter

My program displays a horizontal scrolling surface tiled with UIImageViews from left to right. Code runs on the UI thread to ensure that newly-visible UIImageViews have a freshly loaded UIImage ...

nHibernate Collection Count

I have the following model which I have created and mapped with nHibernate. Using lazy loading so I don t need to get the Vehicles for the Dealer at the start. Public class Dealer { public virtual ...

Fetched Properties v Relationships (Core Data - iPhone)

I m a new iPhone developer (of about 4 months or so) who is starting to look at Core Data. In the "Beginning iPhone 3 Development" book by Dave Mark it mentions that the main difference between ...

Is Shared ReadOnly lazyloaded?

I was wondering when I write Shared ReadOnly Variable As DataType = New DataType() Or alternatively Shared ReadOnly Variable As New DataType() Is it lazy loaded or as the instance initializes? ...

热门标签