DataObjects/Core_enum.php
authorEdward <edward@roojs.com>
Thu, 4 Jun 2015 08:42:46 +0000 (16:42 +0800)
committerEdward <edward@roojs.com>
Thu, 4 Jun 2015 08:42:46 +0000 (16:42 +0800)
DataObjects/Core_enum.php

index 8ca0f22..06d6488 100644 (file)
@@ -338,7 +338,7 @@ class Pman_Core_DataObjects_Core_enum extends DB_DataObject
         
     }
     
-    function merge($id, $roo)
+    function merge($to, $roo)
     {
         $affects  = array();
         
@@ -361,25 +361,22 @@ class Pman_Core_DataObjects_Core_enum extends DB_DataObject
             $chk = DB_DataObject::factory($ka[0]);
             
             if (!is_a($chk,'DB_DataObject')) {
-                $this->jerr('Unable to load referenced table, check the links config: ' .$ka[0]);
+                $roo->jerr('Unable to load referenced table, check the links config: ' .$ka[0]);
             }
-           // print_r(array($chk->tablename() , $ka[1] ,  $xx->tablename() , $this->key ));
-            $chk->{$ka[1]} =  $xx->{$this->key};
+            
+            $chk->{$ka[1]} = $this->id;
 
-            if (count($chk->keys())) {
-                $matches = $chk->count();
-            } else {
-                //DB_DataObject::DebugLevel(1);
-                $matches = $chk->count($ka[1]);
+            foreach ($chk->fetchAll() as $c){
+                $cc = clone ($c);
+                $c->{$ka[1]} = $to;
+                $c->update($o);
             }
-
-            if ($matches) {
-                $chk->_match_key = $ka[1];
-                $match_ar[] = clone($chk);
-                continue;
-            }          
         }
         
+        $this->delete();
+        
+        $roo->jok('Merged');
+        
     }