Doctrine 1
  1. Doctrine 1
  2. DC-797

Records containing a one-to-one relation are hydrated as dirty/modified

    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

      Attached is a self-contained 80 line test. In the test, Foo has an one to one relation to Bar. There is a null value in the foreign key column (at least one Foo without a Bar). And the relation is being used via this DQL:

      Doctrine_Query::create()->from('Foo f')->leftJoin('f.Bar b')->execute();

      At around line 254 of Doctrine_Hydrator_Graph/Graph.php, the hydrator sets the value of the relation column to Doctrine_Null if there is no related record:

      $prev[$parent][$relationAlias] = $this->getNullPointer();

      This causes Doctrine_Record to check if the value of the foreign key field was updated, which it does by calling Doctrine_Record::_isValueModified(). However, that method considers an update from null to Doctrine_Null as a modification. So, the record (and eventually the entire Collection returned) is marked as Doctrine_Record::STATE_DIRTY, even though it contains no modifications. This occurs during hydration, so the caller never sees the record as being clean.

      The workaround I'm using is to subclass Doctrine_Record, and return false from _isValueModified() when moving from null to Doctrine_Null. But I think this could also be fixed in the hydrator.

      1. Record.php.diff
        2 kB
        Derek Price
      2. test.php
        2 kB
        Dominic Scheirlinck

        Activity

        Hide
        Dominic Scheirlinck added a comment -
        Show
        Dominic Scheirlinck added a comment - Patch is here: http://github.com/doctrine/doctrine1/pull/7
        Hide
        Dominic Scheirlinck added a comment -

        New pull request, done on a topic branch this time (and rebased to be much nicer)

        http://github.com/doctrine/doctrine1/pull/8

        Show
        Dominic Scheirlinck added a comment - New pull request, done on a topic branch this time (and rebased to be much nicer) http://github.com/doctrine/doctrine1/pull/8
        Hide
        Derek Price added a comment - - edited

        Record.php.diff contains basically the patch Dominic attached but also makes sure that the internal property value is set regardless of whether the record is marked as dirty or not. Some code will break when the internal property value is left <unset> instead of Doctrine_Null.

        Show
        Derek Price added a comment - - edited Record.php.diff contains basically the patch Dominic attached but also makes sure that the internal property value is set regardless of whether the record is marked as dirty or not. Some code will break when the internal property value is left <unset> instead of Doctrine_Null.

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Dominic Scheirlinck
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: