Browse Source

[Tree - Closure Table] Some fixes on "childCount" property implementation

Gustavo Adrian 14 years ago
parent
commit
80ccbff40f

+ 10 - 1
lib/Gedmo/Tree/Strategy/ORM/Closure.php

@@ -68,6 +68,14 @@ class Closure implements Strategy
     public function processPrePersist($em, $entity)
     {
         $this->pendingChildNodeInserts[] = $entity;
+        
+        $meta = $em->getClassMetadata(get_class($entity));
+        $config = $this->listener->getConfiguration($em, $meta->name);
+        
+        if (isset( $config['childCount'])) {
+            // We set by default 0 on insertions for childCount field
+            $meta->getReflectionProperty($config['childCount'])->setValue($entity, 0);
+        }
     }
     
     /**
@@ -284,5 +292,6 @@ class Closure implements Strategy
      * {@inheritdoc}
      */
     public function onFlushEnd($em)
-    {}
+    {
+    }
 }

+ 1 - 1
tests/Gedmo/Tree/Fixture/Closure/Category.php

@@ -35,7 +35,7 @@ class Category
     
     /**
      * @gedmo:TreeChildCount
-     * @Column(type="integer", nullable="true")
+     * @Column(type="integer")
      */
     private $childCount;