Symfony 2验证代理实体 [英] Symfony 2 Validate Proxy Entity
问题描述
所以我有一个实体注释断言,我在实体上手动调用validate(),一切都按预期工作。
So I have an entity with annotation asserts and I call validate() manually on the entity, everything works as expected.
但是有时候,相同的实体通过关系。然后,当我通常获取实体时,我得到该实体的代理(被初始化),我相信由于性能原因,Doctrine会自动执行此操作。
However sometimes a process before this hydrates the same entity through a relationship. Then later when I fetch the entity normally I get a proxy of that entity (which is initialised), I believe Doctrine does this automatically for performance reasons.
然而,当我然后来验证它,因为该类是一个代理,注释不会被接受。
However when I then come to validate it, because the class is a proxy the annotation asserts don't get picked up.
应该验证()知道如何通过加载断言来验证代理从它的基础,它代理?我假设不是,因为它不是。
Should validate() know how to validate a proxy by loading the asserts from it's base class it proxies from? I assume not since it isn't.
所以我的问题是,有什么办法将代理实体变成它的正常实体类(我不意味着水合物或者是因为已经是初始化了)。
So my question is, is there any way to turn a proxy entity into it's normal entity class (I don't mean hydrate/initialise it because it already is).
还是有办法强制Doctrine从数据库重新获取实体,而不是给我一个初始化的代理? / p>
Or is there a way to force Doctrine to re-fetch the entity from the database and not return me an initialised proxy?
推荐答案
啊,我不得不打电话给$ code $ em-> clear()请求相关实体确保我下一次获得无代理实体。
Ah-ha I had to call $em->clear()
after requesting the related entity to make sure I got a none-proxy entity the next time round.
这篇关于Symfony 2验证代理实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!