Browse Source

added special handling for persistent collections

Johannes Schmitt 12 năm trước cách đây
mục cha
commit
b1fe04f7c9

+ 7 - 0
Serializer/EventDispatcher/Subscriber/DoctrineProxySubscriber.php

@@ -2,6 +2,7 @@
 
 
 namespace JMS\SerializerBundle\Serializer\EventDispatcher\Subscriber;
 namespace JMS\SerializerBundle\Serializer\EventDispatcher\Subscriber;
 
 
+use Doctrine\ORM\PersistentCollection;
 use Doctrine\Common\Persistence\Proxy;
 use Doctrine\Common\Persistence\Proxy;
 use Doctrine\ORM\Proxy\Proxy as ORMProxy;
 use Doctrine\ORM\Proxy\Proxy as ORMProxy;
 use JMS\SerializerBundle\Serializer\EventDispatcher\PreSerializeEvent;
 use JMS\SerializerBundle\Serializer\EventDispatcher\PreSerializeEvent;
@@ -13,6 +14,12 @@ class DoctrineProxySubscriber implements EventSubscriberInterface
     {
     {
         $object = $event->getObject();
         $object = $event->getObject();
 
 
+        if ($object instanceof PersistentCollection) {
+            $event->setType('ArrayCollection');
+
+            return;
+        }
+
         if ( ! $object instanceof Proxy && ! $object instanceof ORMProxy) {
         if ( ! $object instanceof Proxy && ! $object instanceof ORMProxy) {
             return;
             return;
         }
         }