original_string: protected function populateModelFromJoin($result)
      {
          // extract main model
          $model = new $this->modelClass();
          foreach (array_keys(get_object_vars($model)) as $attr) {
              $model->$attr = $result->$attr;
          }
          
          // extract referenced models
          $refs = $model->getReferences();
          $refs2 = (is_array($this->fetchRefs) ? $this->fetchRefs : array_keys($refs));
          sort($refs2);
          foreach ($refs2 as $idx => $name) {
              $prefix = "REF{$idx}_{$name}__";
              
              // handle null result
              if (is_null($result->{$prefix . $refs[$name]['key']})) {
                  $refModel = null;
              } else {
                  $refModel = new $refs[$name]['model']();
                  foreach (array_keys(get_object_vars($refModel)) as $attr) {
                      $refModel->$attr = $result->{$prefix . $attr};
                  }
              }
              
              // inject manager reference
              if ($refModel && $this->manager) {
                  $this->manager->manageModel($refModel);
              }
              
              $model->$name = $refModel;
          }
          
          return $model;
      }
code: protected function populateModelFromJoin($result)
      {
          // extract main model
          $model = new $this->modelClass();
          foreach (array_keys(get_object_vars($model)) as $attr) {
              $model->$attr = $result->$attr;
          }
          
          // extract referenced models
          $refs = $model->getReferences();
          $refs2 = (is_array($this->fetchRefs) ? $this->fetchRefs : array_keys($refs));
          sort($refs2);
          foreach ($refs2 as $idx => $name) {
              $prefix = "REF{$idx}_{$name}__";
              
              // handle null result
              if (is_null($result->{$prefix . $refs[$name]['key']})) {
                  $refModel = null;
              } else {
                  $refModel = new $refs[$name]['model']();
                  foreach (array_keys(get_object_vars($refModel)) as $attr) {
                      $refModel->$attr = $result->{$prefix . $attr};
                  }
              }
              
              // inject manager reference
              if ($refModel && $this->manager) {
                  $this->manager->manageModel($refModel);
              }
              
              $model->$name = $refModel;
          }
          
          return $model;
      }
code_tokens: protected function populateModelFromJoin ( $ result ) { // extract main model $ model = new $ this -> modelClass ( ) ; foreach ( array_keys ( get_object_vars ( $ model ) ) as $ attr ) { $ model -> $ attr = $ result -> $ attr ; } // extract referenced models $ refs = $ model -> getReferences ( ) ; $ refs2 = ( is_array ( $ this -> fetchRefs ) ? $ this -> fetchRefs : array_keys ( $ refs ) ) ; sort ( $ refs2 ) ; foreach ( $ refs2 as $ idx => $ name ) { $ prefix = "REF{$idx}_{$name}__" ; // handle null result if ( is_null ( $ result -> { $ prefix . $ refs [ $ name ] [ 'key' ] } ) ) { $ refModel = null ; } else { $ refModel = new $ refs [ $ name ] [ 'model' ] ( ) ; foreach ( array_keys ( get_object_vars ( $ refModel ) ) as $ attr ) { $ refModel -> $ attr = $ result -> { $ prefix . $ attr } ; } } // inject manager reference if ( $ refModel && $ this -> manager ) { $ this -> manager -> manageModel ( $ refModel ) ; } $ model -> $ name = $ refModel ; } return $ model ; }
docstring: Populate model instance including retrieved references from join query result.
  
  @param object $result    Query result.
  
  @return mixed            Populated model instance.
docstring_tokens: Populate model instance including retrieved references from join query result .