Details

    • Type: Bug Bug
    • Status: Reopened
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.2.0-RC1
    • Fix Version/s: None
    • Component/s: Relations
    • Labels:
      None

      Description

      While implementing a Record_Template and manipulating a query by using the preDqlSelect Event, i got massive problems if the query was generated by a refresh() or refreshRelated() call. I found out that the issue appears because the query has no alias for the table then. This makes it hard to add forther (sub-)selects to the query via preDqlSelect, e.g.

      $params = $event->getParams();
      		$alias = $params['alias'];
      
                      if(!$query->isSubquery() && $alias == $queryClone->getRootAlias()) {	
      				
      				
      				$countQuery = '(SELECT COUNT('.$alias.'_tcount.uid) FROM '.$modelName.' '.$alias.'_tcount WHERE '.$alias.'.'.$groupId.'='.$alias.'_tcount.'.$groupId.') AS '.$this->_options['terminationCount'];
      				
      				$query->addSelect($countQuery);
      			}
      

      The issue is solved by adding an alias in the foreignKey and localKey relation types' fetchRelatedFor methods (at least that's sufficient for my issue, maybe there is a need to add similar lines to the other relation types).

      Doctrine_Relation_ForeignKey (from line 60):

      $alias = $this->getTable()->getComponentName().'_rel';
                  	
                      $dql  = 'FROM ' . $this->getTable()->getComponentName()
                            .' '.$alias. ' WHERE ' . $this->getCondition($alias) . $this->getOrderBy(null, false);
      

      Doctrine_Relation_LocalKey (from line 58):

      $alias = $this->getTable()->getComponentName().'_rel';
              	
                  $dql  = 'FROM ' . $this->getTable()->getComponentName()
                       .' '.$alias. ' WHERE ' . $this->getCondition($alias) . $this->getOrderBy(null, false);
      

        Activity

        Christian Jaentsch created issue -
        Roman S. Borschel made changes -
        Field Original Value New Value
        Assignee Roman S. Borschel [ romanb ] Jonathan H. Wage [ jwage ]
        Jonathan H. Wage made changes -
        Description While implementing a Record_Template and manipulating a query by using the preDqlSelect Event, i got massive problems if the query was generated by a refresh() or refreshRelated() call. I found out that the issue appears because the query has no alias for the table then. This makes it hard to add forther (sub-)selects to the query via preDqlSelect, e.g.

        $params = $event->getParams();
        $alias = $params['alias'];

                        if(!$query->isSubquery() && $alias == $queryClone->getRootAlias()) {


        $countQuery = '(SELECT COUNT('.$alias.'_tcount.uid) FROM '.$modelName.' '.$alias.'_tcount WHERE '.$alias.'.'.$groupId.'='.$alias.'_tcount.'.$groupId.') AS '.$this->_options['terminationCount'];

        $query->addSelect($countQuery);
        }




        The issue is solved by adding an alias in the foreignKey and localKey relation types' fetchRelatedFor methods (at least that's sufficient for my issue, maybe there is a need to add similar lines to the other relation types).



        Doctrine_Relation_ForeignKey (from line 60):

        $alias = $this->getTable()->getComponentName().'_rel';
                    
                        $dql = 'FROM ' . $this->getTable()->getComponentName()
                              .' '.$alias. ' WHERE ' . $this->getCondition($alias) . $this->getOrderBy(null, false);




        Doctrine_Relation_LocalKey (from line 58):

        $alias = $this->getTable()->getComponentName().'_rel';
                
                    $dql = 'FROM ' . $this->getTable()->getComponentName()
                         .' '.$alias. ' WHERE ' . $this->getCondition($alias) . $this->getOrderBy(null, false);
        While implementing a Record_Template and manipulating a query by using the preDqlSelect Event, i got massive problems if the query was generated by a refresh() or refreshRelated() call. I found out that the issue appears because the query has no alias for the table then. This makes it hard to add forther (sub-)selects to the query via preDqlSelect, e.g.

        {code}
        $params = $event->getParams();
        $alias = $params['alias'];

                        if(!$query->isSubquery() && $alias == $queryClone->getRootAlias()) {


        $countQuery = '(SELECT COUNT('.$alias.'_tcount.uid) FROM '.$modelName.' '.$alias.'_tcount WHERE '.$alias.'.'.$groupId.'='.$alias.'_tcount.'.$groupId.') AS '.$this->_options['terminationCount'];

        $query->addSelect($countQuery);
        }
        {code}



        The issue is solved by adding an alias in the foreignKey and localKey relation types' fetchRelatedFor methods (at least that's sufficient for my issue, maybe there is a need to add similar lines to the other relation types).



        Doctrine_Relation_ForeignKey (from line 60):
        {code}
        $alias = $this->getTable()->getComponentName().'_rel';
                    
                        $dql = 'FROM ' . $this->getTable()->getComponentName()
                              .' '.$alias. ' WHERE ' . $this->getCondition($alias) . $this->getOrderBy(null, false);
        {code}



        Doctrine_Relation_LocalKey (from line 58):
        {code}
        $alias = $this->getTable()->getComponentName().'_rel';
                
                    $dql = 'FROM ' . $this->getTable()->getComponentName()
                         .' '.$alias. ' WHERE ' . $this->getCondition($alias) . $this->getOrderBy(null, false);
        {code}
        Hide
        Jonathan H. Wage added a comment -

        If no alias is explicitly defined, the alias is automatically set to the model name. So in your code change you changed it from "ModelName" to "ModelName_rel". If you had the following:

        SELECT * FROM User
        

        The alias would be "User" and it is the same as if you did:

        SELECT * FROM User User
        
        Show
        Jonathan H. Wage added a comment - If no alias is explicitly defined, the alias is automatically set to the model name. So in your code change you changed it from "ModelName" to "ModelName_rel". If you had the following: SELECT * FROM User The alias would be "User" and it is the same as if you did: SELECT * FROM User User
        Jonathan H. Wage made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Invalid [ 6 ]
        Hide
        Christian Jaentsch added a comment -

        unfortunately this does not solve my problem... i narrowed it down to be a problem with addPendingJoinCondition in such a case.

        here is a short scenario of what i want to do...

        $modelName = 'Exhibition';
        $alias = "exhibitionalias";
        $subAlias = 'exhibitionsub';
        		
        $query = Doctrine_Query::create()
        ->from($modelName.' '.$alias);
        		
        $subQuery .= 'SELECT '.$subAlias.'.id FROM '.$modelName.' '.$subAlias.' WHERE '.$subAlias.'.id = '.$alias.'.id';
        $query->addPendingJoinCondition($alias, $alias.'.id IN ('.$subQuery.')');
        		
        $query->execute();
        

        this works so far as the alias is different from the model name... but if i change

        $alias = "Exhibition";
        

        i get the exception

        exception 'Doctrine_Exception' with message 'Couldn't find class exhibitionsub' in /var/www/erh_eeecore/core/lib/Doctrine/Doctrine/Table.php:299
        Stack trace:
        #0 /var/www/erh_eeecore/core/lib/Doctrine/Doctrine/Table.php(249): Doctrine_Table->initDefinition()
        #1 /var/www/erh_eeecore/core/lib/Doctrine/Doctrine/Connection.php(1126): Doctrine_Table->__construct('exhibitionsub', Object(Doctrine_Connection_Mysql), true)
        #2 /var/www/erh_eeecore/core/lib/Doctrine/Doctrine/Query.php(1924): Doctrine_Connection->getTable('exhibitionsub')
        #3 /var/www/erh_eeecore/core/lib/Doctrine/Doctrine/Query.php(1722): Doctrine_Query->loadRoot('exhibitionsub', 'exhibitionsub')
        #4 /var/www/erh_eeecore/core/lib/Doctrine/Doctrine/Query/Where.php(76): Doctrine_Query->load('exhibitionsub', false)
        #5 /var/www/erh_eeecore/core/lib/Doctrine/Doctrine/Query/Condition.php(92): Doctrine_Query_Where->load('exhibitionsub.i...')
        #6 /var/www/erh_eeecore/core/lib/Doctrine/Doctrine/Query/Abstract.php(2077): Doctrine_Query_Condition->parse('exhibitionsub.i...')
        #7 /var/www/erh_eeecore/core/lib/Doctrine/Doctrine/Query.php(1156): Doctrine_Query_Abstract->_processDqlQueryPart('where', Array)
        #8 /var/www/erh_eeecore/core/lib/Doctrine/Doctrine/Query.php(1122): Doctrine_Query->buildSqlQuery(false)
        #9 /var/www/erh_eeecore/core/lib/Doctrine/Doctrine/Query/Abstract.php(1137): Doctrine_Query->getSqlQuery(Array, false)
        #10 /var/www/erh_eeecore/core/lib/Doctrine/Doctrine/Query/Abstract.php(1106): Doctrine_Query_Abstract->_getDqlCallbackComponents(Array)
        #11 /var/www/erh_eeecore/core/lib/Doctrine/Doctrine/Query.php(1143): Doctrine_Query_Abstract->_preQuery()
        #12 /var/www/erh_eeecore/core/lib/Doctrine/Doctrine/Query.php(1122): Doctrine_Query->buildSqlQuery(true)
        #13 /var/www/erh_eeecore/core/lib/Doctrine/Doctrine/Query/JoinCondition.php(87): Doctrine_Query->getSqlQuery()
        #14 /var/www/erh_eeecore/core/lib/Doctrine/Doctrine/Query/Condition.php(92): Doctrine_Query_JoinCondition->load('Exhibition.id I...')
        #15 /var/www/erh_eeecore/core/lib/Doctrine/Doctrine/Query.php(1089): Doctrine_Query_Condition->parse('Exhibition.id I...')
        #16 /var/www/erh_eeecore/core/lib/Doctrine/Doctrine/Query.php(1013): Doctrine_Query->_processPendingJoinConditions('Exhibition')
        #17 /var/www/erh_eeecore/core/lib/Doctrine/Doctrine/Query.php(1228): Doctrine_Query->_buildSqlFromPart()
        #18 /var/www/erh_eeecore/core/lib/Doctrine/Doctrine/Query.php(1122): Doctrine_Query->buildSqlQuery(false)
        #19 /var/www/erh_eeecore/core/lib/Doctrine/Doctrine/Query/Abstract.php(1137): Doctrine_Query->getSqlQuery(Array, false)
        #20 /var/www/erh_eeecore/core/lib/Doctrine/Doctrine/Query/Abstract.php(1106): Doctrine_Query_Abstract->_getDqlCallbackComponents(Array)
        #21 /var/www/erh_eeecore/core/lib/Doctrine/Doctrine/Query/Abstract.php(1001): Doctrine_Query_Abstract->_preQuery(Array)
        #22 /var/www/erh_eeecore/app/modules/default/controllers/ExhibitionsController.php(75): Doctrine_Query_Abstract->execute()
        
        Show
        Christian Jaentsch added a comment - unfortunately this does not solve my problem... i narrowed it down to be a problem with addPendingJoinCondition in such a case. here is a short scenario of what i want to do... $modelName = 'Exhibition'; $alias = "exhibitionalias" ; $subAlias = 'exhibitionsub'; $query = Doctrine_Query::create() ->from($modelName.' '.$alias); $subQuery .= 'SELECT '.$subAlias.'.id FROM '.$modelName.' '.$subAlias.' WHERE '.$subAlias.'.id = '.$alias.'.id'; $query->addPendingJoinCondition($alias, $alias.'.id IN ('.$subQuery.')'); $query->execute(); this works so far as the alias is different from the model name... but if i change $alias = "Exhibition" ; i get the exception exception 'Doctrine_Exception' with message 'Couldn't find class exhibitionsub' in / var /www/erh_eeecore/core/lib/Doctrine/Doctrine/Table.php:299 Stack trace: #0 / var /www/erh_eeecore/core/lib/Doctrine/Doctrine/Table.php(249): Doctrine_Table->initDefinition() #1 / var /www/erh_eeecore/core/lib/Doctrine/Doctrine/Connection.php(1126): Doctrine_Table->__construct('exhibitionsub', Object (Doctrine_Connection_Mysql), true ) #2 / var /www/erh_eeecore/core/lib/Doctrine/Doctrine/Query.php(1924): Doctrine_Connection->getTable('exhibitionsub') #3 / var /www/erh_eeecore/core/lib/Doctrine/Doctrine/Query.php(1722): Doctrine_Query->loadRoot('exhibitionsub', 'exhibitionsub') #4 / var /www/erh_eeecore/core/lib/Doctrine/Doctrine/Query/Where.php(76): Doctrine_Query->load('exhibitionsub', false ) #5 / var /www/erh_eeecore/core/lib/Doctrine/Doctrine/Query/Condition.php(92): Doctrine_Query_Where->load('exhibitionsub.i...') #6 / var /www/erh_eeecore/core/lib/Doctrine/Doctrine/Query/Abstract.php(2077): Doctrine_Query_Condition->parse('exhibitionsub.i...') #7 / var /www/erh_eeecore/core/lib/Doctrine/Doctrine/Query.php(1156): Doctrine_Query_Abstract->_processDqlQueryPart('where', Array) #8 / var /www/erh_eeecore/core/lib/Doctrine/Doctrine/Query.php(1122): Doctrine_Query->buildSqlQuery( false ) #9 / var /www/erh_eeecore/core/lib/Doctrine/Doctrine/Query/Abstract.php(1137): Doctrine_Query->getSqlQuery(Array, false ) #10 / var /www/erh_eeecore/core/lib/Doctrine/Doctrine/Query/Abstract.php(1106): Doctrine_Query_Abstract->_getDqlCallbackComponents(Array) #11 / var /www/erh_eeecore/core/lib/Doctrine/Doctrine/Query.php(1143): Doctrine_Query_Abstract->_preQuery() #12 / var /www/erh_eeecore/core/lib/Doctrine/Doctrine/Query.php(1122): Doctrine_Query->buildSqlQuery( true ) #13 / var /www/erh_eeecore/core/lib/Doctrine/Doctrine/Query/JoinCondition.php(87): Doctrine_Query->getSqlQuery() #14 / var /www/erh_eeecore/core/lib/Doctrine/Doctrine/Query/Condition.php(92): Doctrine_Query_JoinCondition->load('Exhibition.id I...') #15 / var /www/erh_eeecore/core/lib/Doctrine/Doctrine/Query.php(1089): Doctrine_Query_Condition->parse('Exhibition.id I...') #16 / var /www/erh_eeecore/core/lib/Doctrine/Doctrine/Query.php(1013): Doctrine_Query->_processPendingJoinConditions('Exhibition') #17 / var /www/erh_eeecore/core/lib/Doctrine/Doctrine/Query.php(1228): Doctrine_Query->_buildSqlFromPart() #18 / var /www/erh_eeecore/core/lib/Doctrine/Doctrine/Query.php(1122): Doctrine_Query->buildSqlQuery( false ) #19 / var /www/erh_eeecore/core/lib/Doctrine/Doctrine/Query/Abstract.php(1137): Doctrine_Query->getSqlQuery(Array, false ) #20 / var /www/erh_eeecore/core/lib/Doctrine/Doctrine/Query/Abstract.php(1106): Doctrine_Query_Abstract->_getDqlCallbackComponents(Array) #21 / var /www/erh_eeecore/core/lib/Doctrine/Doctrine/Query/Abstract.php(1001): Doctrine_Query_Abstract->_preQuery(Array) #22 / var /www/erh_eeecore/app/modules/ default /controllers/ExhibitionsController.php(75): Doctrine_Query_Abstract->execute()
        Christian Jaentsch made changes -
        Resolution Invalid [ 6 ]
        Status Resolved [ 5 ] Reopened [ 4 ]
        Hide
        Jonathan H. Wage added a comment -

        Hmm. Christian, your issue doesn't seem at all related to the original issue. It seems like an entirely different problem, no?

        Show
        Jonathan H. Wage added a comment - Hmm. Christian, your issue doesn't seem at all related to the original issue. It seems like an entirely different problem, no?
        Hide
        Christian Jaentsch added a comment -

        Well, I don't know where the reason for the problem is exactly... I just solved my problem by adding an alias to the foreignKey and localKey relations. The actual problem seems to be located in how the query is processed if the alias is equal to the name of the "from"-model. this causes problems while adding pending join conditions.

        Show
        Christian Jaentsch added a comment - Well, I don't know where the reason for the problem is exactly... I just solved my problem by adding an alias to the foreignKey and localKey relations. The actual problem seems to be located in how the query is processed if the alias is equal to the name of the "from"-model. this causes problems while adding pending join conditions.
        Hide
        Jonathan H. Wage added a comment -

        Ok, well what you described is totally un-related to this issue. If you have found a bug you can open another ticket with detailed information and a failing test case. Thanks, Jon

        Show
        Jonathan H. Wage added a comment - Ok, well what you described is totally un-related to this issue. If you have found a bug you can open another ticket with detailed information and a failing test case. Thanks, Jon
        Hide
        Jonathan H. Wage added a comment -

        Can you show a patch with your changes?

        Show
        Jonathan H. Wage added a comment - Can you show a patch with your changes?
        Hide
        Christian Jaentsch added a comment -

        My patch is as shown in the description of this issue:

        Doctrine_Relation_ForeignKey (from line 60):

        $alias = $this->getTable()->getComponentName().'_rel';
                    	
                        $dql  = 'FROM ' . $this->getTable()->getComponentName()
                              .' '.$alias. ' WHERE ' . $this->getCondition($alias) . $this->getOrderBy(null, false);
        

        Doctrine_Relation_LocalKey (from line 58):

        $alias = $this->getTable()->getComponentName().'_rel';
                	
                    $dql  = 'FROM ' . $this->getTable()->getComponentName()
                         .' '.$alias. ' WHERE ' . $this->getCondition($alias) . $this->getOrderBy(null, false);
        
        Show
        Christian Jaentsch added a comment - My patch is as shown in the description of this issue: Doctrine_Relation_ForeignKey (from line 60): $alias = $ this ->getTable()->getComponentName().'_rel'; $dql = 'FROM ' . $ this ->getTable()->getComponentName() .' '.$alias. ' WHERE ' . $ this ->getCondition($alias) . $ this ->getOrderBy( null , false ); Doctrine_Relation_LocalKey (from line 58): $alias = $ this ->getTable()->getComponentName().'_rel'; $dql = 'FROM ' . $ this ->getTable()->getComponentName() .' '.$alias. ' WHERE ' . $ this ->getCondition($alias) . $ this ->getOrderBy( null , false );

        This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

        • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DC-290, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

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

            Dates

            • Created:
              Updated: