[limb-svn] r6944 - in 3.x/trunk/limb/active_record: src tests/cases

svn at limb-project.com svn at limb-project.com
Tue Apr 22 09:12:34 MSD 2008


Author: svk
Date: 2008-04-22 09:12:34 +0400 (Tue, 22 Apr 2008)
New Revision: 6944
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6944

Modified:
   3.x/trunk/limb/active_record/src/lmbARManyToManyCollection.class.php
   3.x/trunk/limb/active_record/tests/cases/lmbARManyToManyRelationsTest.class.php
Log:
-- lmbARManyToManyCollection :: set fix + test

Modified: 3.x/trunk/limb/active_record/src/lmbARManyToManyCollection.class.php
===================================================================
--- 3.x/trunk/limb/active_record/src/lmbARManyToManyCollection.class.php	2008-04-21 09:25:34 UTC (rev 6943)
+++ 3.x/trunk/limb/active_record/src/lmbARManyToManyCollection.class.php	2008-04-22 05:12:34 UTC (rev 6944)
@@ -74,7 +74,11 @@
     if(count($to_remove_ids))
     {
       $table = new lmbTableGateway($this->relation_info['table'], $this->conn);
-      $table->delete(lmbSQLCriteria :: in($this->relation_info['foreign_field'], $to_remove_ids));
+      //$table->delete(lmbSQLCriteria :: in($this->relation_info['foreign_field'], $to_remove_ids));
+      $criteria = new lmbSqlCriteria();
+      $criteria->addAnd(new lmbSQLFieldCriteria($this->relation_info['field'], $this->owner->getId()));
+      $criteria->addAnd(new lmbSQLFieldCriteria($this->relation_info['foreign_field'], $to_remove_ids, lmbSQLFieldCriteria :: IN));
+      $table->delete($criteria);
     }
   }
   

Modified: 3.x/trunk/limb/active_record/tests/cases/lmbARManyToManyRelationsTest.class.php
===================================================================
--- 3.x/trunk/limb/active_record/tests/cases/lmbARManyToManyRelationsTest.class.php	2008-04-21 09:25:34 UTC (rev 6943)
+++ 3.x/trunk/limb/active_record/tests/cases/lmbARManyToManyRelationsTest.class.php	2008-04-22 05:12:34 UTC (rev 6944)
@@ -61,7 +61,33 @@
     $this->assertEqual($rs->current()->getTitle(), $group2->getTitle());
     $this->assertEqual($rs->current()->getId(), $group2->getId());
   }
-
+  
+  function testSetRelation()
+  {
+    $user1 = $this->creator->initUser();
+    $user2 = $this->creator->initUser();
+      
+    $group1 = $this->creator->initGroup();
+    $group2 = $this->creator->initGroup();
+      
+    $user1->addToGroups($group1);
+    $user1->addToGroups($group2);
+    $user2->addToGroups($group1);
+    $user2->addToGroups($group2);
+      
+    $user1->save();
+    $user2->save();
+    $this->assertEqual($user1->getGroups()->count(), 2);
+    $this->assertEqual($user2->getGroups()->count(), 2);
+    
+    $user1->getGroups()->set(array($group1));
+    $user1->save();
+    $user2->save();
+     
+    $this->assertEqual($user1->getGroups()->count(), 1);
+    $this->assertEqual($user2->getGroups()->count(), 2);
+  }
+  
   function testLoadShouldNotMixTables()
   {
     $user1 = $this->creator->initUser();



More information about the limb-svn mailing list