[limb-svn] r6017 - in 3.x/trunk/limb/active_record: src tests/cases tests/cases/.fixture
svn at limb-project.com
svn at limb-project.com
Wed Jun 27 12:19:09 MSD 2007
Author: serega
Date: 2007-06-27 12:19:09 +0400 (Wed, 27 Jun 2007)
New Revision: 6017
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6017
Modified:
3.x/trunk/limb/active_record/src/lmbARManyToManyCollection.class.php
3.x/trunk/limb/active_record/tests/cases/.fixture/init_tests.mysql
3.x/trunk/limb/active_record/tests/cases/.fixture/init_tests.oci
3.x/trunk/limb/active_record/tests/cases/.fixture/init_tests.pgsql
3.x/trunk/limb/active_record/tests/cases/.fixture/init_tests.sqlite
3.x/trunk/limb/active_record/tests/cases/lmbARManyToManyCollectionTest.class.php
Log:
-- lmbARManyToManyCollection :: removeAll() removes only those records where 'foreigh_field' field has not NULL values. This functionality tested for mysql and sqlite db drivers.
Modified: 3.x/trunk/limb/active_record/src/lmbARManyToManyCollection.class.php
===================================================================
--- 3.x/trunk/limb/active_record/src/lmbARManyToManyCollection.class.php 2007-06-26 13:31:54 UTC (rev 6016)
+++ 3.x/trunk/limb/active_record/src/lmbARManyToManyCollection.class.php 2007-06-27 08:19:09 UTC (rev 6017)
@@ -66,7 +66,11 @@
protected function _removeRelatedRecords()
{
$table = new lmbTableGateway($this->relation_info['table'], $this->conn);
- $table->delete(new lmbSQLFieldCriteria($this->relation_info['field'], $this->owner->getId()));
+ $criteria = new lmbSQLCriteria();
+ $criteria->addAnd(new lmbSQLFieldCriteria($this->relation_info['field'], $this->owner->getId()));
+ $criteria->addAnd(new lmbSQLFieldCriteria($this->relation_info['foreign_field'], 'NULL', lmbSQLFieldCriteria :: NOT_EQUAL));
+
+ $table->delete($criteria);
}
protected function _saveObject($object, $error_list = null)
Modified: 3.x/trunk/limb/active_record/tests/cases/.fixture/init_tests.mysql
===================================================================
--- 3.x/trunk/limb/active_record/tests/cases/.fixture/init_tests.mysql 2007-06-26 13:31:54 UTC (rev 6016)
+++ 3.x/trunk/limb/active_record/tests/cases/.fixture/init_tests.mysql 2007-06-27 08:19:09 UTC (rev 6017)
@@ -103,3 +103,12 @@
`group_id` bigint(20) default NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+DROP TABLE IF EXISTS `extended_user2group_for_test`;
+CREATE TABLE `extended_user2group_for_test` (
+ `id` bigint(20) NOT NULL auto_increment,
+ `user_id` bigint(20) default NULL,
+ `group_id` bigint(20) default NULL,
+ `other_id` bigint(20) default NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Modified: 3.x/trunk/limb/active_record/tests/cases/.fixture/init_tests.oci
===================================================================
--- 3.x/trunk/limb/active_record/tests/cases/.fixture/init_tests.oci 2007-06-26 13:31:54 UTC (rev 6016)
+++ 3.x/trunk/limb/active_record/tests/cases/.fixture/init_tests.oci 2007-06-27 08:19:09 UTC (rev 6017)
@@ -219,3 +219,20 @@
BEFORE INSERT ON user2group_for_test REFERENCING NEW AS NEW FOR EACH ROW
BEGIN IF :NEW.ID IS NULL THEN SELECT user2group_for_test_seq.NEXTVAL INTO :NEW.ID FROM DUAL; END IF; END;
/
+BEGIN EXECUTE IMMEDIATE 'DROP SEQUENCE extended_user2group_for_test_seq'; EXCEPTION WHEN OTHERS THEN NULL; END;
+/
+CREATE SEQUENCE extended_user2group_for_test_seq;
+/
+BEGIN EXECUTE IMMEDIATE 'DROP TABLE extended_user2group_for_test'; EXCEPTION WHEN OTHERS THEN NULL; END;
+/
+CREATE TABLE extended_user2group_for_test (
+ id number NOT NULL,
+ user_id number default NULL,
+ group_id number default NULL,
+ other_id number default NULL,
+ PRIMARY KEY (id)
+);
+/
+CREATE OR REPLACE TRIGGER extended_user2group_for_test_trigger
+BEFORE INSERT ON extended_user2group_for_test REFERENCING NEW AS NEW FOR EACH ROW
+BEGIN IF :NEW.ID IS NULL THEN SELECT extended_user2group_for_test_seq.NEXTVAL INTO :NEW.ID FROM DUAL; END IF; END;
Modified: 3.x/trunk/limb/active_record/tests/cases/.fixture/init_tests.pgsql
===================================================================
--- 3.x/trunk/limb/active_record/tests/cases/.fixture/init_tests.pgsql 2007-06-26 13:31:54 UTC (rev 6016)
+++ 3.x/trunk/limb/active_record/tests/cases/.fixture/init_tests.pgsql 2007-06-27 08:19:09 UTC (rev 6017)
@@ -116,3 +116,12 @@
PRIMARY KEY (id)
) ;
+DROP TABLE extended_user2group_for_test CASCADE;
+
+CREATE TABLE extended_user2group_for_test (
+ "id" SERIAL,
+ "user_id" int8 default NULL,
+ "group_id" int8 default NULL,
+ "other_id" int8 default NULL,
+ PRIMARY KEY (id)
+) ;
Modified: 3.x/trunk/limb/active_record/tests/cases/.fixture/init_tests.sqlite
===================================================================
--- 3.x/trunk/limb/active_record/tests/cases/.fixture/init_tests.sqlite 2007-06-26 13:31:54 UTC (rev 6016)
+++ 3.x/trunk/limb/active_record/tests/cases/.fixture/init_tests.sqlite 2007-06-27 08:19:09 UTC (rev 6017)
@@ -90,3 +90,11 @@
"user_id" bigint(20) default NULL,
"group_id" bigint(20) default NULL
);
+
+DROP TABLE "extended_user2group_for_test";
+CREATE TABLE "extended_user2group_for_test" (
+ "id" INTEGER PRIMARY KEY,
+ "user_id" bigint(20) default NULL,
+ "group_id" bigint(20) default NULL,
+ "other_id" bigint(20) default NULL
+);
Modified: 3.x/trunk/limb/active_record/tests/cases/lmbARManyToManyCollectionTest.class.php
===================================================================
--- 3.x/trunk/limb/active_record/tests/cases/lmbARManyToManyCollectionTest.class.php 2007-06-26 13:31:54 UTC (rev 6016)
+++ 3.x/trunk/limb/active_record/tests/cases/lmbARManyToManyCollectionTest.class.php 2007-06-27 08:19:09 UTC (rev 6017)
@@ -23,6 +23,16 @@
}
}
+class UserForTestWithSpecialRelationTable extends lmbActiveRecord
+{
+ protected $_db_table_name = 'user_for_test';
+
+ protected $_has_many_to_many = array('groups' => array('field' => 'user_id',
+ 'foreign_field' => 'group_id',
+ 'table' => 'extended_user2group_for_test',
+ 'class' => 'GroupForTest'));
+}
+
class lmbARManyToManyCollectionTest extends UnitTestCase
{
protected $db;
@@ -40,8 +50,10 @@
function _dbCleanUp()
{
- lmbActiveRecord :: delete('GroupForTest');
- lmbActiveRecord :: delete('UserForTest');
+ $this->db->delete('group_for_test');
+ $this->db->delete('user_for_test');
+ $this->db->delete('user2group_for_test');
+ $this->db->delete('extended_user2group_for_test');
}
function testAddToWithExistingOwner()
@@ -314,6 +326,28 @@
$this->assertEqual($collection->count(), 0);
}
+ function testRemoveAllDeletesOnlyProperRecordsFromTable()
+ {
+ $group1 = $this->_initGroup();
+ $group2 = $this->_initGroup();
+
+ $user = new UserForTestWithSpecialRelationTable();
+ $user->setFirstName('User' . mt_rand());
+ $user->save();
+
+ $collection = new lmbARManyToManyCollection('groups', $user);
+ $collection->add($group1);
+ $collection->add($group2);
+
+ $db_table = new lmbTableGateway('extended_user2group_for_test');
+ $db_table->insert(array('user_id' => $user->getId(),
+ 'other_id' => 100));
+
+ $collection->removeAll();
+
+ $this->assertEqual($db_table->select()->count(), 1);
+ }
+
function testPaginateWithNonSavedOwner()
{
$group1 = $this->_initGroup();
More information about the limb-svn
mailing list