Doctrine 1
  1. Doctrine 1
  2. DC-8

Doctrine_Hydrator error while populate records if column contains double underscores

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Invalid
    • Affects Version/s: 1.0.12, 1.1.4, 1.2.0-ALPHA1
    • Fix Version/s: 1.0.12, 1.1.4, 1.2.0-ALPHA1
    • Component/s: Query
    • Labels:

      Description

      Moved from Trac (Ticket #2472) to JIRA.

      I'm starting to use Doctrine for an project which already has an existing database schema. Some of the columns have double underscores as part of their names, e.g. "foo_bar__abc".

      Model:

      Foo:
        tableName: foo_table
        columns:
          foo_bar__abc:
            type: integer
      

      Query:

      $q = Doctrine_Query::create()->from('Foo b')->fetchOne();

      Error:

      Notice: Undefined index: b__foo_bar in Doctrine/Hydrator.php on line 309
      Notice: Undefined index: in Doctrine/Hydrator.php on line 310
      Fatal error: Call to a member function getFieldName() on a non-object in Doctrine/Hydrator.php on line 311
      

      Issue #849 is from the same kind of error but I solved it in another way.

      File: Hydrator.php

      304 if ($this->_isIgnoredName($key)) continue;
      305                
      306 $e = explode('__', $key);
      307 $last = strtolower(array_pop($e));
      

      changed to

      304 if ($this->_isIgnoredName($key)) continue;
      305                
      306 $e = explode('__', $key, 2);
      307 $last = strtolower(array_pop($e));
      

      This will fix the issue without the need to replace the seperator.

        Activity

        Hide
        Jonathan H. Wage added a comment -

        Your change breaks the test suite with fatal errors. I don't think this is something we can change at this point in 1.x

        Show
        Jonathan H. Wage added a comment - Your change breaks the test suite with fatal errors. I don't think this is something we can change at this point in 1.x
        Hide
        Frank Strife added a comment - - edited

        i have found a workaround for this little problem

         
        				$count = substr_count($key, '__');
        				
        				$e = explode('__', $key);
                        $last = strtolower(array_pop($e));
        				if ($count > 1){
        					$cache[$key]['dqlAlias'] = $this->_tableAliases[strtolower(implode('', $e))];
        				}
        				else{
        					$cache[$key]['dqlAlias'] = $this->_tableAliases[strtolower(implode('__', $e))];
        				}
        

        but to call use $example->id not $example->__id

        Show
        Frank Strife added a comment - - edited i have found a workaround for this little problem $count = substr_count($key, '__'); $e = explode('__', $key); $last = strtolower(array_pop($e)); if ($count > 1){ $cache[$key]['dqlAlias'] = $this->_tableAliases[strtolower(implode('', $e))]; } else{ $cache[$key]['dqlAlias'] = $this->_tableAliases[strtolower(implode('__', $e))]; } but to call use $example->id not $example->__id
        Hide
        Jaroslav Hejral added a comment -

        This bug occures again in the 1.2.1 version.

        file: Doctrine/Hydrator/Graph.php

        282: if ($this->_isIgnoredName($key))

        { 283: continue; 284: }

        285:
        286: $e = explode('__', $key); // here is missing the third argument with value 2
        287: $last = strtolower(array_pop($e));

        Show
        Jaroslav Hejral added a comment - This bug occures again in the 1.2.1 version. file: Doctrine/Hydrator/Graph.php 282: if ($this->_isIgnoredName($key)) { 283: continue; 284: } 285: 286: $e = explode('__', $key); // here is missing the third argument with value 2 287: $last = strtolower(array_pop($e));
        Hide
        Edu added a comment - - edited

        Solution:

        In file: Doctrine/Hydrator/Graph.php

        Change this:

        $e = explode('__', $key);
        $last = strtolower(array_pop($e));
        $cache[$key]['dqlAlias'] = $this->_tableAliases[strtolower(implode('__', $e))];
        

        For this:

        $e = explode('__', $key);
        if(count($e)>2){
        	$aux = array($e[0]);
        	unset($e[0]);
        	$ls_builder = '';
        	foreach($e as $value)
                {
        		$ls_builder .= '__'.$value;
        	}
        	array_push($aux,$ls_builder);
        	$e = $aux;
        }
        $last = strtolower(array_pop($e));
        $cache[$key]['dqlAlias'] = $this->_tableAliases[strtolower(implode('__', $e))];
        
        Show
        Edu added a comment - - edited Solution: In file: Doctrine/Hydrator/Graph.php Change this: $e = explode('__', $key); $last = strtolower(array_pop($e)); $cache[$key]['dqlAlias'] = $ this ->_tableAliases[strtolower(implode('__', $e))]; For this: $e = explode('__', $key); if (count($e)>2){ $aux = array($e[0]); unset($e[0]); $ls_builder = ''; foreach($e as $value) { $ls_builder .= '__'.$value; } array_push($aux,$ls_builder); $e = $aux; } $last = strtolower(array_pop($e)); $cache[$key]['dqlAlias'] = $ this ->_tableAliases[strtolower(implode('__', $e))];

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Enrico Stahn
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: