logo       

4107 - in trunk/PersistentObject: . docs tests tests/data [eZComponents: Do: msg#00277

web.ezcomponents.cvs

Subject: 4107 - in trunk/PersistentObject: . docs tests tests/data [eZComponents: Docs]

Author: Tobias Schlitt
Date: 2006-11-28 14:34:36 +0100 (Tue, 28 Nov 2006)
New Revision: 4107

Log:
- Fixed issue #9249: Save/update objects with 1:1 relations that share the
same ID does not work.

Modified:
trunk/PersistentObject/ChangeLog
trunk/PersistentObject/docs/tutorial.txt
trunk/PersistentObject/tests/data/relationtestbirthday.php
trunk/PersistentObject/tests/one_to_one_relation_test.php

Modified: trunk/PersistentObject/ChangeLog
===================================================================
--- trunk/PersistentObject/ChangeLog 2006-11-28 13:07:09 UTC (rev 4106)
+++ trunk/PersistentObject/ChangeLog 2006-11-28 13:34:36 UTC (rev 4107)
@@ -8,6 +8,8 @@
PersistentObjectDatabaseSchemaTiein.
- Fixed issue #9591: persistentsession attempts to throw non existing
exception (typo).
+- Fixed issue #9249: Save/update objects with 1:1 relations that share the
+ same ID does not work.


1.2beta2 - Monday 20 November 2006

Modified: trunk/PersistentObject/docs/tutorial.txt
===================================================================
--- trunk/PersistentObject/docs/tutorial.txt 2006-11-28 13:07:09 UTC (rev
4106)
+++ trunk/PersistentObject/docs/tutorial.txt 2006-11-28 13:34:36 UTC (rev
4107)
@@ -642,6 +642,52 @@
relation records. If you delete a record, all it's relation records are deleted
automatically.

+Special 1:1 relations
+---------------------
+
+If you desire to use 1:1 relations, where 2 tables share a common primary key,
+you need to define 1 table to generate the key and the other table to use the
+ezcPersistentManualGenerator. For our example, if one person may only have one
+address, this could look like that: ::
+
+ <?php
+ $def = new ezcPersistentObjectDefinition();
+ $def->table = "addresses";
+ $def->class = "Address";
+
+ $def->idProperty = new ezcPersistentObjectIdProperty;
+ $def->idProperty->columnName = 'id';
+ $def->idProperty->propertyName = 'id';
+ $def->idProperty->generator = new ezcPersistentGeneratorDefinition(
'ezcPersistentManualGenerator' );
+
+ // ...
+ ?>
+
+And for the relation (defined in the definition file of the Person): ::
+
+ <?php
+ // ...
+
+ $def->relations["Address"] = new ezcPersistentOneToOneRelation(
+ "persons",
+ "addresses"
+ );
+ $def->relations["Address"]->columnMap = array(
+ new ezcPersistentSingleTableMap(
+ "id",
+ "person_id"
+ ),
+ );
+ ?>
+
+If you let both tables use an ezcPersistentSequenceGenerator for the same key,
+ezcPersistentSession will fail to save a related object, since the ID will
+already be set by the ezcPersistentSession::addRelatedObject() method.
+
+Another way to make this working is, to not use the same primary key for both
+tables, but to make the Address object have its own ID and only use the Persons
+ID as a foreign key.
+
Reverse relations
-----------------


Modified: trunk/PersistentObject/tests/data/relationtestbirthday.php
===================================================================
--- trunk/PersistentObject/tests/data/relationtestbirthday.php 2006-11-28
13:07:09 UTC (rev 4106)
+++ trunk/PersistentObject/tests/data/relationtestbirthday.php 2006-11-28
13:34:36 UTC (rev 4107)
@@ -8,7 +8,7 @@
$def->idProperty = new ezcPersistentObjectIdProperty;
$def->idProperty->columnName = 'person_id';
$def->idProperty->propertyName = 'person';
-$def->idProperty->generator = new ezcPersistentGeneratorDefinition(
'ezcPersistentSequenceGenerator' );
+$def->idProperty->generator = new ezcPersistentGeneratorDefinition(
'ezcPersistentManualGenerator' );

$def->properties['birthday'] = new ezcPersistentObjectProperty;
$def->properties['birthday']->columnName = 'birthday';

Modified: trunk/PersistentObject/tests/one_to_one_relation_test.php
===================================================================
--- trunk/PersistentObject/tests/one_to_one_relation_test.php 2006-11-28
13:07:09 UTC (rev 4106)
+++ trunk/PersistentObject/tests/one_to_one_relation_test.php 2006-11-28
13:34:36 UTC (rev 4107)
@@ -264,7 +264,7 @@
);
}

- // Fails currently, since PO thinks the object is already persistent
+ // Works now, using manual generator
public function testAddRelatedBirthdayToPerson3SaveSuccess()
{
$person = $this->session->load( "RelationTestPerson", 3 );
@@ -291,7 +291,7 @@
);
}

- public function testAddRelatedBirthdayToPerson3UpdateFailure()
+ public function testAddRelatedBirthdayToPerson3UpdateSuccess()
{
$person = $this->session->load( "RelationTestPerson", 3 );

@@ -302,11 +302,14 @@

$this->session->addRelatedObject( $person, $birthday );

+ $this->session->update( $birthday );
+
try
{
- $this->session->update( $birthday );
+ // The birthday record should not exist
+ $birthday = $this->session->load( "RelationTestBirthday", 3 );
}
- catch( Exception $e )
+ catch ( Exception $e )
{
return;
}



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise