Doctrine 1
  1. Doctrine 1
  2. DC-16

postHydrate listeners should be called after relationships are loaded.

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Blocker Blocker
    • Resolution: Invalid
    • Affects Version/s: 1.2.0-ALPHA1, 1.2.2
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      Doctrine 1.1.3 calls post hydration listeners before relationships are loaded.

      This O patch caches the information needed to call the listeners and calls the listeners in reverse order after all the data has been loaded. The net effect is that postHydrate listeners are called for all an object's children before being called for a parent object.

      Memory cost should be minor (O @ two pointers per record), and the (additional) processing cost should be flat and almost zero (n function calls to postHydrate have simply been moved outside the loop to a second loop). There is an additional call to $table->getComponentName() in the second loop that could be eliminated by storing $componentName with the other event initializers in the new stack).

      1. Doctrine-real-postHydrate.diff
        10 kB
        Roman S. Borschel
      2. Doctrine-real-postHydrate(2).diff
        0.6 kB
        Jonathan H. Wage

        Activity

        Hide
        Jonathan H. Wage added a comment -

        This patch no longer applies as the hydration code is re factored a lot in 1.2

        Show
        Jonathan H. Wage added a comment - This patch no longer applies as the hydration code is re factored a lot in 1.2
        Hide
        Exception e added a comment -

        It seems that even after the rewrite postHydrate() doesn't work correctly.

        class Member extends BaseMember 
               private $roles = array();
        
        	function postHydrate($event)	{
        		if ($this->relatedExists('Artist'))	{
        			array_push($this->roles, 'artist');
        		}
        		
        	}
        }
        

        throws exception «Unknown record property / related component "member_id" on "Member"», even if I have joined the related object Artist. member_id is the PK of Member.

        Trying isset in

        function postHydrate($event) {
        if (isset($this->Artist)))

        { array_push($this->roles, 'artist'); }

        }

        will consistently return false.

        This is a blocker since there is no workaround. postHydrate is the last event on record loading afaik.

        Show
        Exception e added a comment - It seems that even after the rewrite postHydrate() doesn't work correctly. class Member extends BaseMember private $roles = array(); function postHydrate($event) { if ($ this ->relatedExists('Artist')) { array_push($ this ->roles, 'artist'); } } } throws exception «Unknown record property / related component "member_id" on "Member"», even if I have joined the related object Artist. member_id is the PK of Member. Trying isset in function postHydrate($event) { if (isset($this->Artist))) { array_push($this->roles, 'artist'); } } will consistently return false. This is a blocker since there is no workaround. postHydrate is the last event on record loading afaik.

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Roman S. Borschel
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: