You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Commits
-------
200ed54 [DoctrineBridge] Extracted the common type and made the choice list generic
3c81b62 [Doctrine] Cleanup and move loader into its own method
7646a5b [Doctrine] Dont allow null in ORMQueryBuilderLoader
988c2a5 Adjust check
3b5c617 [DoctrineBridge] Remove large parts of the EntityChoiceList code that were completly unnecessary (code was unreachable).
b919d92 [DoctrineBridge] Optimize fetching of entities to use WHERE IN and fix other inefficencies.
517eebc [DoctrineBridge] Refactor entity choice list to be ORM independant using an EntityLoader interface.
Discussion
----------
[DoctrineBridge] Refactor EntityChoiceList
Bug fix: no
Feature addition: yes
Backwards compatibility break: no (99%)
Symfony2 tests pass: yes
This decouples the ORM from the EntityChoiceList and makes its much more flexible. Instead of having a "query_builder" to do smart or complex queries you can now create "loader" instances which can arbitrarily help loading entities.
Additionally i removed lots of code that was unnecessary and not used by the current code.
There is a slight BC break in that the EntityChoiceList class is now accepting an EntityLoaderInterface instead of a querybuilder. However that class was nested inside the EntityType and should not be widely used or overwritten.
The abstract class DoctrineType is meant to be used as base class by other Doctrine project to share the logic by simply using a different type name and a different loader implementation.
This PR replaces #2728.
---------------------------------------------------------------------------
by beberlei at 2011/12/19 09:20:43 -0800
Thanks for doing the last refactorings, this is now fine from my side as well.
// Otherwise expect a __toString() method in the entity
108
+
thrownewFormException('Entities passed to the choice field must have a "__toString()" method defined (or you can also override the "property" option).');
127
109
}
128
110
129
111
if (!is_array($choices) && !$choicesinstanceof \Closure && !is_null($choices)) {
@@ -219,11 +201,6 @@ private function loadEntities($entities, $group = null)
219
201
// If the property option was given, use it
220
202
$value = $this->propertyPath->getValue($entity);
221
203
} else {
222
-
// Otherwise expect a __toString() method in the entity
223
-
if (!method_exists($entity, '__toString')) {
224
-
thrownewFormException('Entities passed to the choice field must have a "__toString()" method defined (or you can also override the "property" option).');
225
-
}
226
-
227
204
$value = (string) $entity;
228
205
}
229
206
@@ -278,7 +255,7 @@ public function getEntities()
278
255
}
279
256
280
257
/**
281
-
* Returns the entity for the given key.
258
+
* Returns the entities for the given keys.
282
259
*
283
260
* If the underlying entities have composite identifiers, the choices
284
261
* are initialized. The key is expected to be the index in the choices
@@ -287,55 +264,26 @@ public function getEntities()
287
264
* If they have single identifiers, they are either fetched from the
288
265
* internal entity cache (if filled) or loaded from the database.
289
266
*
290
-
* @param string $key The choice key (for entities with composite
291
-
* identifiers) or entity ID (for entities with single
292
-
* identifiers)
293
-
*
294
-
* @return object The matching entity
267
+
* @param array $keys The choice key (for entities with composite
268
+
* identifiers) or entity ID (for entities with single
0 commit comments