Browse Source

Merge pull request #241 from tolean/feature/treeClosure_with_custom_columns

get column definition from metadata
Gediminas Morkevicius 13 years ago
parent
commit
38b055e651
1 changed files with 20 additions and 6 deletions
  1. 20 6
      lib/Gedmo/Tree/Strategy/ORM/Closure.php

+ 20 - 6
lib/Gedmo/Tree/Strategy/ORM/Closure.php

@@ -170,6 +170,15 @@ class Closure implements Strategy
     public function processScheduledDelete($em, $entity)
     {}
 
+    protected function getJoinColumnFieldName($association)
+    {
+        if (count($association['joinColumnFieldNames']) > 1) {
+            throw new RuntimeException('More association on field '.$association['fieldName']);
+        }
+
+        return array_shift($association['joinColumnFieldNames']);
+    }
+
     /**
      * {@inheritdoc}
      */
@@ -191,11 +200,16 @@ class Closure implements Strategy
             $closureClass = $config['closure'];
             $closureMeta = $em->getClassMetadata($closureClass);
             $closureTable = $closureMeta->getTableName();
+
+            $ancestorColumnName = $this->getJoinColumnFieldName($em->getClassMetadata($config['closure'])->getAssociationMapping('ancestor'));
+            $descendantColumnName = $this->getJoinColumnFieldName($em->getClassMetadata($config['closure'])->getAssociationMapping('descendant'));
+            $depthColumnName = $em->getClassMetadata($config['closure'])->getColumnName('depth');
+
             $entries = array(
                 array(
-                    'ancestor' => $nodeId,
-                    'descendant' => $nodeId,
-                    'depth' => 0
+                    $ancestorColumnName => $nodeId,
+                    $descendantColumnName => $nodeId,
+                    $depthColumnName => 0
                 )
             );
 
@@ -209,9 +223,9 @@ class Closure implements Strategy
 
                 foreach ($ancestors as $ancestor) {
                     $entries[] = array(
-                        'ancestor' => $ancestor['ancestor']['id'],
-                        'descendant' => $nodeId,
-                        'depth' => $ancestor['depth'] + 1
+                        $ancestorColumnName => $ancestor['ancestor']['id'],
+                        $descendantColumnName => $nodeId,
+                        $depthColumnName => $ancestor['depth'] + 1
                     );
                 }
             }