Doctrine 1
  1. Doctrine 1
  2. DC-196

Saving related records from relations doen't work

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: 1.1.4
    • Fix Version/s: None
    • Component/s: Connection
    • Labels:
      None
    • Environment:
      Debian 5.0.3, PHP 5.2.11-0.dotdeb.1 with Suhosin-Patch 0.9.7

      Description

      Hello guys,

      at first my ERM:

      [Table1] --1---*--> [Table1Sub] --1---1--> [Table2] --1---*--> [Table2Sub]

      I want to add datasets in Table1, Table1Sub and Table2Sub. Table2 already has a dataset. So I try

      <?php
      $table1 = new Table1;
      $table1->fromArray($someDataForTable1);
      
      $table1sub = new Table1Sub;
      $table1sub->fromArray($someDataForTable1Sub); // table2_id is set, so everything is right
      
      $table2sub = new Table2Sub;
      $table2sub->fromArray($someDataForTable2Sub);
      
      $table1sub->table2->table2sub[] = $table2sub;
      $table1->table1sub[] = $table1sub;
      
      $table1->save();
      ?>

      Doctrine saves all datasets but Table2Sub.

      I reversed engineer a while, and found in Doctrine_Connection_UnitOfWork::saveRelatedLocalKeys() the if condition isModified().
      So, Table2Sub is not saved, because Table2 is not modified. When a changed it to isModified(true), Doctine saves everything.

      Is it possible to add the attached patch?

      BTW: Can somebody add a 'return $this' in Doctrine_Record::fromArray()?

      Greets,
      Dominik

        Activity

        Hide
        Jonathan H. Wage added a comment -

        It is not this way due to performance reasons. Checking if any related records are dirty would be too slow. If you want to force it to save you can change the state of the object manually.

        $obj->state('DIRTY');
        
        Show
        Jonathan H. Wage added a comment - It is not this way due to performance reasons. Checking if any related records are dirty would be too slow. If you want to force it to save you can change the state of the object manually. $obj->state('DIRTY');
        Hide
        Dominik Winter added a comment -

        Our workaround is to save $table2 manually, because this is more readable in my point of view.

        $table2->save();

        Manipulating the state of record looks like a hack.

        Maybe you can implement a saveDeep() method in Doctrine_Record?

        Show
        Dominik Winter added a comment - Our workaround is to save $table2 manually, because this is more readable in my point of view. $table2->save(); Manipulating the state of record looks like a hack. Maybe you can implement a saveDeep() method in Doctrine_Record?
        Hide
        Benoît Guchet added a comment -

        I strongly agree with Dominik.

        Often I construct hierarchies of new objects, possibly with only the "leaf" ones having "real properties" modified.
        It's very hard to deal with that...

        Show
        Benoît Guchet added a comment - I strongly agree with Dominik. Often I construct hierarchies of new objects, possibly with only the "leaf" ones having "real properties" modified. It's very hard to deal with that...

          People

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

            Dates

            • Created:
              Updated:
              Resolved: