Doctrine 1
  1. Doctrine 1
  2. DC-774

Cannot fromArray a toArray with many to many records

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.2.2
    • Fix Version/s: None
    • Component/s: Record, Relations
    • Labels:
      None

      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

        Hide
        Jeff Chu added a comment -

        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.

        Show
        Jeff Chu added a comment - 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.

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Jeff Chu
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: