阅读对象仍然存在,但尚未被教义冲刷

发布于 2024-12-11 18:23:49 字数 879 浏览 0 评论 0原文

我是 symfony2 和学说的新手。 这就是所看到的问题。 我无法

$repository = $this->getDoctrine()->getRepository('entity');
$my_object = $repository->findOneBy($index);

在持久化但尚未刷新的对象上使用 : ! 我认为 getRepository 从数据库读取,所以它不会找到未刷新的对象。

我的问题:如何读取那些持久存在的对象(我认为它们位于“教义会话”中的某个位置)以在刷新整个批次之前重新使用它们?

每个配置文件都有 256 个物理羽流。

每个配置文件都分配有 1 个 plumeOptions 记录。

plumeOptions中,我有一个cartridgeplume,它是PhysicalPlume的FK。

每个羽流均由 ID(自动生成)和 INDEX(用户生成)标识。

规则:我说配置文件 1 已连接到 physical_plume_index 编号 3 (=index)。

现在,我想将一个配置文件及其所有相关数据复制到另一个配置文件。

新的配置文件已创建。新的 256 个羽流被创建并从旧的配置文件中复制。

我想将新的配置文件链接到新的羽流指数 3。

请在此处查看:http://pastebin .com/WFa8vkt1

I'm new to symfony2 and doctrine.
here is the problem as I see it.
i cannot use :

$repository = $this->getDoctrine()->getRepository('entity');
$my_object = $repository->findOneBy($index);

on an object that is persisted, BUT NOT FLUSHED YET !!
i think getRepository read from DB, so it will not find a not-flushed object.

my question: how to read those objects that are persisted (i think they are somewhere in a "doctrine session") to re-use them before i do flush my entire batch ?

every profile has 256 physical plumes.

every profile has 1 plumeOptions record assigned to it.

In plumeOptions, I have a cartridgeplume which is a FK for PhysicalPlume.

every plume is identified by ID (auto-generated) and an INDEX (user-generated).

rule: I say profile 1 has physical_plume_index number 3 (=index) connected to it.

now, I want to copy a profile with all its related data to another profile.

new profile is created. New 256 plumes are created and copied from older profile.

i want to link the new profile to the new plume index 3.

check here: http://pastebin.com/WFa8vkt1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梨涡 2024-12-18 18:23:49

我想你可能想看看这个函数:

$entityManager->getUnitOfWork()->getScheduledEntityInsertions()

给你一个仍然存在的实体对象的列表。

嗯,我没有真正阅读你的问题,通过上面的内容,你将检索完整列表(作为数组),但你不能像使用 getRepository 那样查询它。我会尝试为你找到一些东西..

I think you might want to have a look at this function:

$entityManager->getUnitOfWork()->getScheduledEntityInsertions()

Gives you back a list of entity objects which are persisting yet.

Hmm, I didn't really read your question well, with the above you will retrieve a full list (as an array) but you cannot query it like with getRepository. I will try found something for u..

疑心病 2024-12-18 18:23:49

我认为你可能从错误的角度看待问题。 Doctrine 是你的持久层和数据库访问层。一旦对象进入内存,域模型就有责任提供对对象的访问。所以问题归结为如何在没有持久层的情况下获取对象的引用

您在哪里创建稍后需要获取的对象?创建对象的方法/服务是否可以返回对控制器的引用,以便将其传播到您需要的其他地方?您可以调度一个在应用程序中其他地方侦听的事件来获取该对象吗?

在我看来,Doctrine 应该在应用程序启动时(尽早)使用,以初始化域模型,并在应用程序关闭时使用,以在请求期间保留对域模型的任何更改。在我看来,使用存储库在请求中间获取对象可能是一种代码味道,您应该看看如何重构应用程序流程以消除这种需求。

I think you might look at the problem from the wrong angle. Doctrine is your persistance layer and database access layer. It is the responsibility of your domain model to provide access to objects once they are in memory. So the problem boils down to how do you get a reference to an object without the persistance layer?

Where do you create the object you need to get hold of later? Can the method/service that create the object return a reference to the controller so it can propagate it to the other place you need it? Can you dispatch an event that you listen to elsewhere in your application to get hold of the object?

In my opinion, Doctrine should be used at the startup of the application (as early as possible), to initialize the domain model, and at the shutdown of the application, to persist any changes to the domain model during the request. To use a repository to get hold of objects in the middle of a request is, in my opinion, probably a code smell and you should look at how the application flow can be refactored to remove that need.

坠似风落 2024-12-18 18:23:49

您实际上是一个业务逻辑问题。

在数据库中查询尚未刷新的对象上的 findby 查询,意味着在函数范围内增加更多的数据库层查询对象。

另请记住,findOneBy 还将检索先前保存的具有相同功能的其他对象。

如果您只需要在那些新创建的对象中查找,则应该将它们放入会话数组变量中,并使用 foreach 迭代它们。

如果您需要混合已保存的项目和一些新项目,您应该分别威胁这两个部分,一个使用 foreach ,另一个使用存储库查询!

Your is a business logic problem effectively.

Querying down the Database a findby Query on Object that are not flushed yet, means heaving much more the DB layer querying object that you have already in your function scope.

Also Keep in mind a findOneBy will retrieve also other object previously saved with same features.

If you need to find only among those new created objects, you should make f.e. them in a Session Array Variable, and iterate them with the foreach.

If you need a mix of already saved items + some new items, you should threate the 2 parts separately, one with a foreach , other one with the repository query!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文