Author: ts
Date: Mon Jan 21 20:54:12 2008
New Revision: 7219
Log:
- Implemented delete cascading for multi-relations.
- Finished implementation of enhancement #10373: Several relations to the same
table for PersistentObject.
Modified:
trunk/PersistentObject/ChangeLog
trunk/PersistentObject/src/handlers/delete_handler.php
trunk/PersistentObject/tests/multi_relation_test.php
Modified: trunk/PersistentObject/ChangeLog
==============================================================================
--- trunk/PersistentObject/ChangeLog [iso-8859-1] (original)
+++ trunk/PersistentObject/ChangeLog [iso-8859-1] Mon Jan 21 20:54:12 2008
@@ -2,6 +2,8 @@
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Refactored ezcPersistentSession.
+- Implemented enhancement #10373: Several relations to the same table for
+ PersistentObject.
- Fixed issue #10205: binding variables with an undeclared var doesn't throw
an exception. If getState() on a persistent object does not return an array
an exception is thrown now.
Modified: trunk/PersistentObject/src/handlers/delete_handler.php
==============================================================================
--- trunk/PersistentObject/src/handlers/delete_handler.php [iso-8859-1]
(original)
+++ trunk/PersistentObject/src/handlers/delete_handler.php [iso-8859-1] Mon Jan
21 20:54:12 2008
@@ -280,31 +280,41 @@
* @param object $object The persistent object.
* @param string $relatedClass The class of the related
persistent
* object.
- * @param ezcPersistentRelation $relation The relation to check.
+ * @param ezcPersistentRelation|ezcPersistentRelationCollection $relation
The relation to check.
*
* @todo Revise cascading code. So far it sends 1 delete statement per
* object but we can also collect them table wise and send just 1
* for each table.
*/
- private function cascadeDelete( $object, $relatedClass,
ezcPersistentRelation $relation )
- {
+ private function cascadeDelete( $object, $relatedClass, $relation,
$relationName = null )
+ {
+ // New multi-relations for a single class
+ if ( $relation instanceof ezcPersistentRelationCollection )
+ {
+ foreach( $relation as $relationName => $realRelation )
+ {
+ $this->cascadeDelete( $object, $relatedClass, $realRelation,
$relationName );
+ }
+ }
+
// Remove relation records for ManyToMany relations
if ( $relation instanceof ezcPersistentManyToManyRelation )
{
$relatedObjects = $this->session->loadHandler->getRelatedObjects(
$object,
- $relatedClass
+ $relatedClass,
+ $relationName
);
foreach ( $relatedObjects as $relatedObject )
{
// Determine the correct direction for removal.
if ( $relation->reverse === true )
{
- $this->removeRelatedObject( $relatedObject, $object );
+ $this->removeRelatedObject( $relatedObject, $object,
$relationName );
}
else
{
- $this->removeRelatedObject( $object, $relatedObject );
+ $this->removeRelatedObject( $object, $relatedObject,
$relationName );
}
}
}
@@ -325,7 +335,8 @@
}
$relatedObjects = $this->session->loadHandler->getRelatedObjects(
$object,
- $relatedClass
+ $relatedClass,
+ $relationName
);
foreach ( $relatedObjects as $relatedObject )
{
Modified: trunk/PersistentObject/tests/multi_relation_test.php
==============================================================================
--- trunk/PersistentObject/tests/multi_relation_test.php [iso-8859-1] (original)
+++ trunk/PersistentObject/tests/multi_relation_test.php [iso-8859-1] Mon Jan
21 20:54:12 2008
@@ -414,6 +414,83 @@
'Incorrect number of relation records after removing all siblings.'
);
}
+
+ public function testDeleteCascade()
+ {
+ $mother = $this->session->load( 'MultiRelationTestPerson', 1 );
+
+ $this->session->delete( $mother );
+
+ $q = $this->session->createFindQuery( 'MultiRelationTestPerson' );
+ $q->where(
+ $q->expr->eq(
+ 'mother',
+ $q->bindValue( 1 )
+ )
+ );
+
+ $stmt = $q->prepare();
+ $stmt->execute();
+ $rows = $stmt->fetchAll( PDO::FETCH_ASSOC );
+
+ $this->assertEquals(
+ 0,
+ count( $rows ),
+ "Cascading while deleting MultiRelationTestPerson mother did not
work."
+ );
+ }
+
+ public function testDeleteNoCascade()
+ {
+ $father = $this->session->load( 'MultiRelationTestPerson', 2 );
+
+ $this->session->delete( $father );
+
+ $q = $this->session->createFindQuery( 'MultiRelationTestPerson' );
+ $q->where(
+ $q->expr->eq(
+ 'father',
+ $q->bindValue( 2 )
+ )
+ );
+
+ $stmt = $q->prepare();
+ $stmt->execute();
+ $rows = $stmt->fetchAll( PDO::FETCH_ASSOC );
+
+ $this->assertNotEquals(
+ 0,
+ count( $rows ),
+ "Cascaded while deleting MultiRelationTestPerson father while
cascade was not desired."
+ );
+ }
+
+ public function testRemoveRelatioRecordsOnDeleteSiblings()
+ {
+ $child = $this->session->load( 'MultiRelationTestPerson', 3 );
+
+ $this->session->delete( $child );
+
+ $q = $this->session->database->createSelectQuery();
+ $q->select( '*' )
+ ->from( 'PO_sibling' )
+ ->where(
+ $q->expr->eq(
+ $this->session->database->quoteIdentifier( 'person' ),
+ $q->bindValue( $child->id )
+ )
+ );
+
+ $stmt = $q->prepare();
+ $stmt->execute();
+ $rows = $stmt->fetchAll( PDO::FETCH_ASSOC );
+
+ $this->assertEquals(
+ 0,
+ count( $rows ),
+ 'Incorrect number of relation records after removing all siblings.'
+ );
+ }
}
?>
--
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components