浏览代码

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

Gustavo Adrian 14 年之前
父节点
当前提交
80ccbff40f
共有 2 个文件被更改,包括 11 次插入2 次删除
  1. 10 1
      lib/Gedmo/Tree/Strategy/ORM/Closure.php
  2. 1 1
      tests/Gedmo/Tree/Fixture/Closure/Category.php

+ 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;