Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix bug #478

Avoid clearing references on BaseObject in __sleep method
because this breaks setting foreign references. By cloning the
BaseObject itself we ensure the the Baseobject itself is not
changing when calculating the has code
Added Unit-Tests for the bug
  • Loading branch information...
commit 5d6883862122344a5ad8df1ffac621a99c7a3c38 1 parent 4f33db4
@danez danez authored
View
2  runtime/lib/om/BaseObject.php
@@ -292,7 +292,7 @@ public function hashCode()
return crc32(serialize($this->getPrimaryKey()));
}
- return crc32(serialize($this));
+ return crc32(serialize(clone $this));
}
/**
View
37 test/testsuite/generator/builder/om/GeneratedObjectRelTest.php
@@ -178,6 +178,43 @@ public function testOneToManyGetter()
$this->assertNotNull($books->getCurrent(), 'getRelCol() initialize the internal iterator at the beginning');
}
+ public function testOneToManySetterIsNotLoosingRelation()
+ {
+ $author = new Author();
+ $author->setFirstName('John');
+ $author->setLastName('Doe');
+ $book = new Book();
+ $book->setTitle('Foo4');
+ $book->setISBN('1234');
+
+ $book->setAuthor($author);
+
+ $this->assertNotNull($book->getAuthor(), 'setRel is clearing reference on object');
+ }
+
+ public function testOneToManySetterColelctionIsNotLoosingRelation()
+ {
+ $author = new Author();
+ $author->setFirstName('John');
+ $author->setLastName('Doe');
+ $book1 = new Book();
+ $book1->setTitle('Foo4');
+ $book1->setISBN('1234');
+ $book2 = new Book();
+ $book2->setTitle('Foo6');
+ $book2->setISBN('1239');
+
+ $author->addBook($book1);
+ $author->addBook($book2);
+
+ $books = $author->getBooks();
+ $this->assertCount(2, $books, 'setRelCol is losing references to object');
+
+ foreach ($books as $book) {
+ $this->assertNotNull($book->getAuthor(), 'setRelCol is losing backreference on set object');
+ }
+ }
+
public function testManyToManyCounterExists()
{
$this->assertTrue(method_exists('BookClubList', 'countBooks'), 'Object generator correcly adds counter for the crossRefFk');
Please sign in to comment.
Something went wrong with that request. Please try again.