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} |