Doctrine 1
  1. Doctrine 1
  2. DC-878

cannot access the version models using object->CLASSNAMEVersion in v1.2.3

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.2.3
    • Fix Version/s: None
    • Component/s: Behaviors
    • Labels:
      None
    • Environment:
      PHP Version 5.2.10-2ubuntu6.5 ; Suhosin Patch 0.9.7 ; Ubuntu 9.10 2.6.31-22-generic x86_64 ; Apache/2.2.12 (Ubuntu) PHP/5.2.10-2ubuntu6.5 with Suhosin-Patch ; Doctrine 1.2.3

      Description

      In Doctrine 1.1 if I said

      $vAaaaa = Doctrine::getTable('Aaaaa')->find(1);
      print_r( $vAaaaa->AaaaaVersion ); // print_r( $vAaaaa->AaaaaVersion[0]->toArray() );

      then I got the corresponding version model/array. Our application is using this nice behaviour at several places. But then the project got upgraded to Doctrine 1.2.3, and since then it dies saying

      Unknown record property / related component "UserVersion" on "User" on line 55 of file /home/roland/www/cabcall/library/Doctrine/Doctrine/Record/Filter/Standard.php
      #0 /home/roland/www/cabcall/library/Doctrine/Doctrine/Record.php(1395): Doctrine_Record_Filter_Standard->filterGet(Object(User), 'UserVersion')
      #1 /home/roland/www/cabcall/library/Doctrine/Doctrine/Record.php(1350): Doctrine_Record->_get('UserVersion', true)
      #2 /home/roland/www/cabcall/library/Doctrine/Doctrine/Access.php(72): Doctrine_Record->get('UserVersion')
      #3 /home/roland/www/cabcall/application/controllers/TestController.php(12): Doctrine_Access->__get('UserVersion')
      #4 /home/roland/www/cabcall/library/Zend/Controller/Action.php(513): TestController->indexAction()
      #5 /home/roland/www/cabcall/library/Zend/Controller/Dispatcher/Standard.php(295): Zend_Controller_Action->dispatch('indexAction')
      #6 /home/roland/www/cabcall/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
      #7 /home/roland/www/cabcall/library/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch()
      #8 /home/roland/www/cabcall/library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
      #9 /home/roland/www/cabcall/public/index.php(64): Zend_Application->run()
      #10

      {main}

      Here is the exact example I tried before posting:

      Aaaaa:
          tableName: aaaaa
          columns:
              something:
                  type: integer(8)
                  unsigned: false
                  notnull: true
                  default: 0
          actAs:
              Versionable:
                  versionColumn: version
                  className: %CLASS%Version
                  auditLog: true
                  deleteVersions: true
      
      
      class AaaaaTable extends Doctrine_Table
      {
          /**
           * Returns an instance of this class.
           *
           * @return object AaaaaTable
           */
          public static function getInstance()
          {
              return Doctrine_Core::getTable('Aaaaa');
          }
      }
      
      
      abstract class BaseAaaaa extends Doctrine_Record
      {
      
          public function setTableDefinition()
          {
              $this->setTableName('aaaaa');
              $this->hasColumn('something', 'integer', 8, array(
                   'type' => 'integer',
                   'unsigned' => false,
                   'notnull' => true,
                   'default' => 0,
                   'length' => '8',
                   ));
      
              $this->option('type', 'INNODB');
              $this->option('collate', 'utf8_general_ci');
              $this->option('charset', 'utf8');
          }
      
          public function setUp()
          {
              parent::setUp();
              $versionable0 = new Doctrine_Template_Versionable(array(
                   'versionColumn' => 'version',
                   'className' => '%CLASS%Version',
                   'auditLog' => true,
                   'deleteVersions' => true
                   ));
      
              $this->actAs($versionable0);
          }
      
      }
      
      
      class Aaaaa extends BaseAaaaa
      {
      
      }
      
      
      /*
      $vAaaaa = New Aaaaa;
      $vAaaaa->something = 1;
      $vAaaaa->save();
      */
      
      $vAaaaa = Doctrine::getTable('Aaaaa')->find(1);
      
      print_r( $vAaaaa->AaaaaVersion );
      
      

        Activity

        Hide
        Roland Huszti added a comment -
        <?php
        
        class OSS_Resource_Doctrine extends Zend_Application_Resource_ResourceAbstract
        {
            /**
             * Holds the Doctrine instance
             *
             * @var
             */
            protected $_doctrine;
        
        
            public function init()
            {
                // Return Doctrine so bootstrap will store it in the registry
                return $this->getDoctrine();
            }
        
        
            public function getDoctrine()
            {
                if ( null === $this->_doctrine )
                {
                    // Get Doctrine configuration options from the application.ini file
                    $doctrineConfig = $this->getOptions();
        
                    require_once 'Doctrine.php';
        
                    $loader = Zend_Loader_Autoloader::getInstance();
                    $loader->pushAutoloader( array( 'Doctrine', 'autoload' ) );
                    $loader->pushAutoloader( array( 'Doctrine', 'modelsAutoload' ) );
        
                    $manager = Doctrine_Manager::getInstance();
        
                    $manager->setAttribute( Doctrine::ATTR_MODEL_LOADING, Doctrine::MODEL_LOADING_CONSERVATIVE );
                    $manager->setAttribute( Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES, true );
                    $manager->setAttribute( Doctrine::ATTR_USE_DQL_CALLBACKS, true );
        
                    $manager->setCollate( 'utf8_unicode_ci' );
                    $manager->setCharset( 'utf8' );
        
                    Doctrine::loadModels( $doctrineConfig['models_path'] );
        
                    $db_profiler = new Doctrine_Connection_Profiler();
        
                    $manager->openConnection( $doctrineConfig['connection_string'] );
                    $manager->connection()->setListener( $db_profiler );
        
                    $manager->connection()->setCollate('utf8_unicode_ci');
                    $manager->connection()->setCharset('utf8');
        
                    Zend_Registry::set( 'db_profiler', $db_profiler );
        
                    $this->_doctrine = $manager;
                }
        
                return $this->_doctrine;
            }
        
            /**
             * Set the classes $_doctrine member
             *
             * @param $doctrine The object to set
             */
            public function setDoctrine( $doctrine )
            {
                $this->_doctrine = $doctrine;
            }
        
        }
        
        
        Show
        Roland Huszti added a comment - <?php class OSS_Resource_Doctrine extends Zend_Application_Resource_ResourceAbstract { /** * Holds the Doctrine instance * * @var */ protected $_doctrine; public function init() { // Return Doctrine so bootstrap will store it in the registry return $this->getDoctrine(); } public function getDoctrine() { if ( null === $this->_doctrine ) { // Get Doctrine configuration options from the application.ini file $doctrineConfig = $this->getOptions(); require_once 'Doctrine.php'; $loader = Zend_Loader_Autoloader::getInstance(); $loader->pushAutoloader( array( 'Doctrine', 'autoload' ) ); $loader->pushAutoloader( array( 'Doctrine', 'modelsAutoload' ) ); $manager = Doctrine_Manager::getInstance(); $manager->setAttribute( Doctrine::ATTR_MODEL_LOADING, Doctrine::MODEL_LOADING_CONSERVATIVE ); $manager->setAttribute( Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES, true ); $manager->setAttribute( Doctrine::ATTR_USE_DQL_CALLBACKS, true ); $manager->setCollate( 'utf8_unicode_ci' ); $manager->setCharset( 'utf8' ); Doctrine::loadModels( $doctrineConfig['models_path'] ); $db_profiler = new Doctrine_Connection_Profiler(); $manager->openConnection( $doctrineConfig['connection_string'] ); $manager->connection()->setListener( $db_profiler ); $manager->connection()->setCollate('utf8_unicode_ci'); $manager->connection()->setCharset('utf8'); Zend_Registry::set( 'db_profiler', $db_profiler ); $this->_doctrine = $manager; } return $this->_doctrine; } /** * Set the classes $_doctrine member * * @param $doctrine The object to set */ public function setDoctrine( $doctrine ) { $this->_doctrine = $doctrine; } }
        Hide
        Roland Huszti added a comment -

        To have this very nice and useful feature, I had to add these lines by hand to my audited table's models. Not to the base models, those are overwritten every time you migrate to a new version! Also, in the YAML file you can set the classname to whatever you want, so you need to use the same name in the model, too!

        MODEL

        class XYZ extends BaseXYZ
        
        {
        
        
            public function setUp()
        
            {
        
                parent::setUp();
        
                $this->hasMany('XYZVersion', array( 'local' => 'id', 'foreign' => 'id'));
        
                // you may get the classname from the model, so then you only need to copy-paste the exact same piece of setUp() code into every model you want to
            }
        
        
            . . .
        

        YAML

            actAs:
                Versionable:
                    versionColumn: version
                    className: %CLASS%Version    # this is the default, User -> UserVersion , Address -> AddressVersion, etc.
                    auditLog: true
                    deleteVersions: true
        
        Show
        Roland Huszti added a comment - To have this very nice and useful feature, I had to add these lines by hand to my audited table's models. Not to the base models, those are overwritten every time you migrate to a new version! Also, in the YAML file you can set the classname to whatever you want, so you need to use the same name in the model, too! MODEL class XYZ extends BaseXYZ { public function setUp() { parent::setUp(); $this->hasMany('XYZVersion', array( 'local' => 'id', 'foreign' => 'id')); // you may get the classname from the model, so then you only need to copy-paste the exact same piece of setUp() code into every model you want to } . . . YAML actAs: Versionable: versionColumn: version className: %CLASS%Version # this is the default, User -> UserVersion , Address -> AddressVersion, etc. auditLog: true deleteVersions: true

          People

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

            Dates

            • Created:
              Updated: