Doctrine 1
  1. Doctrine 1
  2. DC-740

issue with multiple connection handling

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.2.2
    • Fix Version/s: 1.2.2
    • Component/s: Connection
    • Labels:
      None

      Description

      I've found an issue where doctrine will use the wrong connection for tables under certain conditions.

      In a template, I'm doing a $sf_user->hasCredential() - which is causing this to be run in sfGuardSecurityUser,

      $this->user = Doctrine::getTable('sfGuardUser')->find($id);
      

      When this execute, the calls find themselves to Doctrine_Manager::getConnectionForComponent($componentName)

      This method calls Doctrine_Core::modelsAutoload($componentName);, which fails to load the class, and returns false (no checking is done to see if it should return true).

      As this fails to include the sfGuardUser classes wher the component binding goes on, the getTAble call will use the default connection, then create the table fails to use the correct connection

      Doctrine_Core::getTable()

      return Doctrine_Manager::getInstance()->getConnectionForComponent($componentName)->getTable($componentName);
      

      the binding is done after the call to getConectionForComponent, as it's getTable that will ultimately cause the autoloader to pull in the table classes.

      1. doctrine_manager.patch
        2 kB
        Marcel Berteler
      2. doctrine_core.patch
        0.7 kB
        Marcel Berteler

        Activity

        Hide
        Marcel Berteler added a comment -

        The patch to Doctrine_Core

        This is a hack that only works when used in sfDoctrinePlugin / Symfony

        Not intended as the final patch to fix this bug but as a work around to make multiple connections usable.

        Show
        Marcel Berteler added a comment - The patch to Doctrine_Core This is a hack that only works when used in sfDoctrinePlugin / Symfony Not intended as the final patch to fix this bug but as a work around to make multiple connections usable.
        Hide
        Ian P. Christian added a comment - - edited

        This effects migrations too it seems:

        Even doing this:

        
            $manager = Doctrine_Manager::getInstance();                                                          
            $manager->bindComponent('ChangeRequest', 'nosp');                                                    
            $manager->bindComponent('change_request', 'nosp');                                                   
        class Addstatetochangerequest extends Doctrine_Migration_Base                                            
        {                                                                                                        
          public function up()                                                                                   
          {                                                                                                      
            $this->addColumn('change_request', 'change_state', 'enum', array('values' => array('draft', 'submitted', 'approved', 'rejected', 'closed')));
        

        This results in:

        
        # ./symfony doctrine:migrate
        >> doctrine  Migrating from version 0 to 1
                                                                                                                                                                                            
          The following errors occurred:                                                                                                                                                    
                                                                                                                                                                                            
           - SQLSTATE[42S02]: Base table or view not found: 1146 Table 'nosp_test_radius2.change_request' doesn't exist. Failing Query: "ALTER TABLE change_request ADD change_state TEXT"  
        

        The database attempted to be used there is not the correct one.

        Show
        Ian P. Christian added a comment - - edited This effects migrations too it seems: Even doing this: $manager = Doctrine_Manager::getInstance(); $manager->bindComponent('ChangeRequest', 'nosp'); $manager->bindComponent('change_request', 'nosp'); class Addstatetochangerequest extends Doctrine_Migration_Base { public function up() { $ this ->addColumn('change_request', 'change_state', ' enum ', array('values' => array('draft', 'submitted', 'approved', 'rejected', 'closed'))); This results in: # ./symfony doctrine:migrate >> doctrine Migrating from version 0 to 1 The following errors occurred: - SQLSTATE[42S02]: Base table or view not found: 1146 Table 'nosp_test_radius2.change_request' doesn't exist. Failing Query: "ALTER TABLE change_request ADD change_state TEXT" The database attempted to be used there is not the correct one.
        Hide
        Marcel Berteler added a comment -

        second required patch to make Symfony work with 2 concurrent databases

        Show
        Marcel Berteler added a comment - second required patch to make Symfony work with 2 concurrent databases
        Hide
        Eugeniy Belyaev added a comment -
        Another bad way to get it working in symfony:


        ProjectConfiguration.class.php
          public function configureDoctrine(Doctrine_Manager $manager)
          {
            $files = sfFinder::type('file')
              ->maxdepth(0)
              ->not_name('*Table.class.php')
              ->name('*.class.php')
              ->in(sfConfig::get('sf_lib_dir') . '/model/doctrine');
        
            foreach ($files as $file) {
              $class_name = str_replace('.class.php', '', basename($file));
              Doctrine_Core::loadModel($class_name, $file);
            }
          }
        
        Show
        Eugeniy Belyaev added a comment - Another bad way to get it working in symfony: ProjectConfiguration.class.php public function configureDoctrine(Doctrine_Manager $manager) { $files = sfFinder::type('file') ->maxdepth(0) ->not_name('*Table.class.php') ->name('*.class.php') ->in(sfConfig::get('sf_lib_dir') . '/model/doctrine'); foreach ($files as $file) { $class_name = str_replace('.class.php', '', basename($file)); Doctrine_Core::loadModel($class_name, $file); } }
        Hide
        Dean de Bree added a comment -

        I found that if I changed the getTable function inside the Core.php file it seemed to work. Basically it forces the autoloader to load the object file, and when it does this it runs the bound connection statement to bind a table to a connection.

        Core.php
        /**
             * Get the Doctrine_Table object for the passed model
             *
             * @param string $componentName
             * @return Doctrine_Table
             */
            public static function getTable($componentName)
            {
                if (!class_exists($componentName)) {
                    new $componentName();
                }
        
                return Doctrine_Manager::getInstance()->getConnectionForComponent($componentName)->getTable($componentName);
            }
        
        Show
        Dean de Bree added a comment - I found that if I changed the getTable function inside the Core.php file it seemed to work. Basically it forces the autoloader to load the object file, and when it does this it runs the bound connection statement to bind a table to a connection. Core.php /** * Get the Doctrine_Table object for the passed model * * @param string $componentName * @ return Doctrine_Table */ public static function getTable($componentName) { if (!class_exists($componentName)) { new $componentName(); } return Doctrine_Manager::getInstance()->getConnectionForComponent($componentName)->getTable($componentName); }

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Ian P. Christian
          • Votes:
            3 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

            • Created:
              Updated: