Details
Description
When working with a many to many record, if you toArray then synchronizeWithArray/fromArray the result - you get an exception.
This appears to be due to the fact that toArray returns collections of array(0 => false) (because a record is in a locked state) and fromArray will attempt to link() the refClass (which has multiple identifiers).
Here's a test that should show this behavior:
class Doctrine_Ticket_DC774_TestCase extends Doctrine_UnitTestCase { public function prepareTables() { $this->tables[] = 'EntityAddress'; $this->tables[] = 'Book'; parent::prepareTables(); } public function prepareData() { $user = new User(); $user->name = 'TestUser'; $address = new Address(); $address->address = 'TestAddress'; $user->Addresses[] = $address; $user->save(); } public function testToArraySynchronizeWithManyToMany() { $user = Doctrine_Core::getTable('User')->findOneByName('TestUser'); $user->refreshRelated(); $user->synchronizeWithArray($user->toArray()); } public function testToArrayFromManyToMany() { $user = Doctrine_Core::getTable('User')->findOneByName('TestUser'); $user->refreshRelated(); $user->fromArray($user->toArray()); } }
Activity
Jeff Chu
made changes -
| Field | Original Value | New Value |
|---|---|---|
| Attachment | doctrine-link.patch [ 10687 ] |
Jeff Chu
made changes -
| Description |
When working with a many to many record, if you {{toArray}} and {{synchronizeWithArray}}/{{fromArray}} the result - you get an exception. This appears to be due to the fact that {{toArray}} returns collections of {{array(0 => false)}} (because a record is in a locked state) and {{fromArray}} will attempt to {{link()}} the {{refClass}} (which has multiple identifiers). Here's a test that should show this behavior: {code} class Doctrine_SynchronizeTest_TestCase extends Doctrine_UnitTestCase { public function prepareTables() { $this->tables[] = 'EntityAddress'; $this->tables[] = 'Book'; parent::prepareTables(); } public function prepareData() { $user = new User(); $user->name = 'TestUser'; $address = new Address(); $address->address = 'TestAddress'; $user->Addresses[] = $address; $user->save(); } public function testToArraySynchronizeWithManyToMany() { $user = Doctrine_Core::getTable('User')->findOneByName('TestUser'); $user->refreshRelated(); $user->synchronizeWithArray($user->toArray()); } public function testToArrayFromManyToMany() { $user = Doctrine_Core::getTable('User')->findOneByName('TestUser'); $user->refreshRelated(); $user->fromArray($user->toArray()); } } {code} |
When working with a many to many record, if you {{toArray}} and {{synchronizeWithArray}}/{{fromArray}} the result - you get an exception. This appears to be due to the fact that {{toArray}} returns collections of {{array(0 => false)}} (because a record is in a locked state) and {{fromArray}} will attempt to {{link()}} the {{refClass}} (which has multiple identifiers). Here's a test that should show this behavior: {code} class Doctrine_Ticket_DC774_TestCase extends Doctrine_UnitTestCase { public function prepareTables() { $this->tables[] = 'EntityAddress'; $this->tables[] = 'Book'; parent::prepareTables(); } public function prepareData() { $user = new User(); $user->name = 'TestUser'; $address = new Address(); $address->address = 'TestAddress'; $user->Addresses[] = $address; $user->save(); } public function testToArraySynchronizeWithManyToMany() { $user = Doctrine_Core::getTable('User')->findOneByName('TestUser'); $user->refreshRelated(); $user->synchronizeWithArray($user->toArray()); } public function testToArrayFromManyToMany() { $user = Doctrine_Core::getTable('User')->findOneByName('TestUser'); $user->refreshRelated(); $user->fromArray($user->toArray()); } } {code} |
Jeff Chu
made changes -
| Description |
When working with a many to many record, if you {{toArray}} and {{synchronizeWithArray}}/{{fromArray}} the result - you get an exception. This appears to be due to the fact that {{toArray}} returns collections of {{array(0 => false)}} (because a record is in a locked state) and {{fromArray}} will attempt to {{link()}} the {{refClass}} (which has multiple identifiers). Here's a test that should show this behavior: {code} class Doctrine_Ticket_DC774_TestCase extends Doctrine_UnitTestCase { public function prepareTables() { $this->tables[] = 'EntityAddress'; $this->tables[] = 'Book'; parent::prepareTables(); } public function prepareData() { $user = new User(); $user->name = 'TestUser'; $address = new Address(); $address->address = 'TestAddress'; $user->Addresses[] = $address; $user->save(); } public function testToArraySynchronizeWithManyToMany() { $user = Doctrine_Core::getTable('User')->findOneByName('TestUser'); $user->refreshRelated(); $user->synchronizeWithArray($user->toArray()); } public function testToArrayFromManyToMany() { $user = Doctrine_Core::getTable('User')->findOneByName('TestUser'); $user->refreshRelated(); $user->fromArray($user->toArray()); } } {code} |
When working with a many to many record, if you {{toArray}} then {{synchronizeWithArray}}/{{fromArray}} the result - you get an exception. This appears to be due to the fact that {{toArray}} returns collections of {{array(0 => false)}} (because a record is in a locked state) and {{fromArray}} will attempt to {{link()}} the {{refClass}} (which has multiple identifiers). Here's a test that should show this behavior: {code} class Doctrine_Ticket_DC774_TestCase extends Doctrine_UnitTestCase { public function prepareTables() { $this->tables[] = 'EntityAddress'; $this->tables[] = 'Book'; parent::prepareTables(); } public function prepareData() { $user = new User(); $user->name = 'TestUser'; $address = new Address(); $address->address = 'TestAddress'; $user->Addresses[] = $address; $user->save(); } public function testToArraySynchronizeWithManyToMany() { $user = Doctrine_Core::getTable('User')->findOneByName('TestUser'); $user->refreshRelated(); $user->synchronizeWithArray($user->toArray()); } public function testToArrayFromManyToMany() { $user = Doctrine_Core::getTable('User')->findOneByName('TestUser'); $user->refreshRelated(); $user->fromArray($user->toArray()); } } {code} |
This list may be incomplete, as errors occurred whilst retrieving source from linked applications:
- Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DC-774, expand=changesets[-21:-1].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)
I doubt this is the right way to fix this, but we wrote in a patch that has the link() function ignore relations that with multiple identifiers. I figured this would be alright since linking those in directly don't make too much sense anyways.
It seems to pass the doctrine test suite. I've attached the patch in case anyone is curious.