symfony/symfony — Issue #2826: "Entities passed to the choice field must be managed" when result cache is active with a TypeForm and a field with a ManyToOne.
Author: armetiz
Created: 2011-12-09 11:15:20+00:00
State: open

Hi there,
Title explain the problem, an exception is throw : "Entities passed to the choice field must be managed" when result cache (APC / XCache, but not InMemory array ) is active with a TypeForm and a field with a ManyToOne contain data.

Example :
BookEntity contains a manyToOne UserEntity.

FormType :
```php
$builder->add('user', 'entity', array ("class" => "Entity\User", "property" => "username"));
```

When creating the FormType, I inject the BookEntity. I have tried to load the BookEntity with and without UserEntity relation.
In both case, a query is made to load the linked UserEntity. And in both case, after that UserEntity is load, the UnitOfWork & EntityManager say that UserEntity isn't managed.

1. I'm not understand how it could be possible that the UserEntity can be correctly load and be un-managed by UnitOfWork & EntityManager without any call to detach/clear/close..

2. Also, I'm not understand why linked UserEntity to BookEntity is fetch from database even If I load it using DQL.

Maybe the problem is linked to the 2. point. Because, If I load Book & User using one DQL, why User is still loaded after FormType creation.

I hope that you can help me around this. I hope that is not a bug.
Right now, I have to disable APC / XCache / Memcache for data result when work with forms..

Armetiz.