<!-- 
RSS generated by JIRA (5.2.7#850-sha1:b2af0c8dc8537b36121c6a579fabbdf79fc919e5) at Tue May 21 15:53:37 UTC 2013

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary add field=key&field=summary to the URL of your request.
For example:
http://www.doctrine-project.org/jira/si/jira.issueviews:issue-xml/DC-373/DC-373.xml?field=key&field=summary
-->
<rss version="0.92" >
<channel>
    <title>Doctrine Project</title>
    <link>http://www.doctrine-project.org/jira</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>5.2.7</version>
        <build-number>850</build-number>
        <build-date>21-02-2013</build-date>
    </build-info>

<item>
            <title>[DC-373] Relating to Translation table (generated by Doctrine_I18n) doesn&apos;t work correctly after resetting connection</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-373</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;Relating to Translation table (generated by Doctrine_I18n) doesn&apos;t work correctly after resetting connection.&lt;/p&gt;

&lt;p&gt;First, I defined the following schema.yml::&lt;/p&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-none&quot;&gt; 
  Example:
    actAs:
      I18n:
        fields: [title]
    columns:
        title: string(128)
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Next, I prepared the following fixture &lt;a href=&quot;file::&quot; class=&quot;external-link&quot;&gt;file::&lt;/a&gt;&lt;/p&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-none&quot;&gt; 
  Example:
    Example_1:
      Translation:
        en:
          title: &quot;Title&quot;
        ja:
          title: &quot;&#38988;&#21517;&quot;
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Next, I run &quot;build-all-reload&quot; task. The table was created and data was loaded.&lt;/p&gt;

&lt;p&gt;And I write the following code::&lt;/p&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt; 
  Doctrine_Core::loadModels(&apos;models&apos;);
  $example = Doctrine_Core::getTable(&apos;Example&apos;)-&amp;gt;find(1);
  
  var_dump(
    $example-&amp;gt;Translation[&apos;en&apos;]-&amp;gt;title,
    $example-&amp;gt;Translation[&apos;ja&apos;]-&amp;gt;title
  );
  
  Doctrine_Manager::resetInstance();
  Doctrine_Manager::getInstance()-&amp;gt;openConnection(DSN, &apos;doctrine&apos;);
  
  $example2 = Doctrine_Core::getTable(&apos;Example&apos;)-&amp;gt;find(1);
  var_dump(
    $example2-&amp;gt;Translation[&apos;en&apos;]-&amp;gt;title,
    $example2-&amp;gt;Translation[&apos;ja&apos;]-&amp;gt;title
  );
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I try executing my code, but I got the following error::&lt;/p&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-none&quot;&gt;  string(5) &quot;Title&quot;
  string(6) &quot;&#38988;&#21517;&quot;
  
  Doctrine_Connection_Mysql_Exception: SQLSTATE[42S22]: Column not found: 1054 Unknown column &apos;e.title&apos; in &apos;field list&apos; in /path/to/doctrine/Doctrine/Connection.php on line 1082
  
  Call Stack:
      0.0055      65352   1. {main}() /path/to/my/code/test.php:0
      0.2776    5873388   2. Doctrine_Table-&amp;gt;find() /path/to/my/code/test.php:52
      0.2793    5881152   3. Doctrine_Query-&amp;gt;fetchOne() /path/to/doctrine/Doctrine/Table.php:1611
      0.2793    5881296   4. Doctrine_Query_Abstract-&amp;gt;execute() /path/to/doctrine/Doctrine/Query.php:281
      0.2793    5881892   5. Doctrine_Query_Abstract-&amp;gt;_execute() /path/to/doctrine/Doctrine/Query/Abstract.php:1026
      0.3127    5890712   6. Doctrine_Connection-&amp;gt;execute() /path/to/doctrine/Doctrine/Query/Abstract.php:976
      0.3164    5892632   7. Doctrine_Connection_Statement-&amp;gt;execute() /path/to/doctrine/Doctrine/Connection.php:1006
      0.3181    5907408   8. Doctrine_Connection-&amp;gt;rethrowException() /path/to/doctrine/Doctrine/Connection/Statement.php:269
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</description>
                <environment>PHP 5.2.11 (with Suhosin-Patch 0.9.7)&lt;br/&gt;
PHP 5.3.6</environment>
            <key id="10638">DC-373</key>
            <summary>Relating to Translation table (generated by Doctrine_I18n) doesn&apos;t work correctly after resetting connection</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/open.png">Open</status>
                    <resolution id="-1">Unresolved</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="co3k">Kousuke Ebihara</reporter>
                        <labels>
                    </labels>
                <created>Sun, 20 Dec 2009 22:54:24 +0000</created>
                <updated>Tue, 11 Sep 2012 13:16:23 +0000</updated>
                                    <version>1.2.1</version>
                <version>1.2.2</version>
                <version>1.2.3</version>
                <version>1.2.4</version>
                                                <component>Connection</component>
                <component>I18n</component>
                        <due></due>
                    <votes>2</votes>
                        <watches>3</watches>
                        <comments>
                    <comment id="14659" author="arnaud.charlier@gmail.com" created="Tue, 2 Nov 2010 04:55:46 +0000"  >&lt;p&gt;Good Morning,&lt;/p&gt;

&lt;p&gt;First, thanks a lot for your work on Doctrine. It&apos;s a real great tool we love to use.&lt;/p&gt;

&lt;p&gt;Currently in one of our big application we have exactly the same issue.&lt;br/&gt;
It seems when we close the connection, the reference with the objectTranslation is lost.&lt;br/&gt;
Re-open the connection seems not able to reinstantiate this Translation link to the objectTranslation.&lt;/p&gt;

&lt;p&gt;Currently we have no solution, but we are still investigating this.&lt;/p&gt;

&lt;p&gt;I&apos;m available to go deep in the code with you, but any Doctrine Team help will be really nice.&lt;/p&gt;

&lt;p&gt;Thanks to let me know as soon as possible.&lt;/p&gt;

&lt;p&gt;Arnaud&lt;/p&gt;</comment>
                    <comment id="15891" author="jsiponen" created="Fri, 27 May 2011 14:51:51 +0000"  >&lt;p&gt;I&apos;ve just now battled with the very same problem in Doctrine 1.2 (the version bundled with symfony 1.4) and the problem seems to be caused by the fact that Doctrine_Record_Generator simply isn&apos;t written such that it is able to reinitialize generators for unloaded table instances after a connection is closed.  This problem also manifests itself after a table has been loaded in a connection and one tries retrieve a table again after Doctrine_Connection-&amp;gt;evictTables() has been called. This makes it impossible to to open more than one connection at a time in a request/script when using behaviors that dynamically modify table instances (such as the i18n behavior).&lt;/p&gt;

&lt;p&gt;Doctrine_Record_Generator determines if it needs to run its initialization methods simply by checking if the to-be generated class, as defined by the className option, exists using a class_exists call. This means that the first time this method is called the initialization happens but for every subsequent call no initialization is made. Now, in the i18m behavior, the important initialization happens in its setTableDefinition method in which it removes any of the translated fields from the table instance that is been setup and redefines them as relations on the to-be-created Translation class. It then finishes off by dynamically declaring the new class for the translation record using its generateClassFromTable method.&lt;/p&gt;

&lt;p&gt;Thus, the first time everything goes smoothly and the i18n generator&apos;s setTableDefinition is called and the table instance is properly initialized. Everything will now work as expected while the current connection is open since the connection instance keeps the i18n modified table instances alive and well for callers.&lt;/p&gt;

&lt;p&gt;But, when the current connection is closed the i18n modified table instances it holds are also removed (goes out of scope). Then, when a new connection is opened, this new connection will start without having any table instances. This means that the next time one asks the new connection for a table instance of the same class with the i18n behavior the i18n behaviors will fail to initialize because the generator at this time believes its class has actually been initialized which, in turn, means that the table using the i18n behavior isn&apos;t properly initialized. No initialization means that this table will now include the non-existant i18n fields in the select part of its queries (those are in the translation table) causing those queries to fail miserably.&lt;/p&gt;

&lt;p&gt;I believe this could be fixed by adding a static attribute to Doctrine_Record_Generator that tracks the spl_object_hash of the underlying dbh instance variable of the doctrine connection of the table parameter. If the hash is the same the next time that the initialize method is called the generator can decide not to reinitialize itself but if it detects that the hash of the current connection is different then that is definitely a clue to the generator that it needs to reinitialize itself (i.e. run all of the initialization methods but generateClassFromTable which should&apos;t be called more than once).&lt;/p&gt;

&lt;p&gt;Maybe do it like this perhaps:&lt;/p&gt;

&lt;div class=&quot;preformatted panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;preformattedContent panelContent&quot;&gt;
&lt;pre&gt; 
abstract class Doctrine_Record_Generator extends Doctrine_Record_Abstract
{
  public function initialize(Doctrine_Table $table)
  {
    /* ... */ 
  
    $currentConnectionHash = spl_object_hash($table-&amp;gt;getConnection()-&amp;gt;getDbh());
    
    //Next part is called if this is the first connection made or if this is a new open connection with new table instances
    if ($currentConnectionHash != self::$lastConnectionHash)
    {
      self::$lastConnectionHash = $currentConnectionHash;
      
      $this-&amp;gt;buildTable();

      $fk = $this-&amp;gt;buildForeignKeys($this-&amp;gt;_options[&apos;table&apos;]);

      $this-&amp;gt;_table-&amp;gt;setColumns($fk);

      $this-&amp;gt;buildRelation();

      $this-&amp;gt;setTableDefinition();
      $this-&amp;gt;setUp();
      
      if ($this-&amp;gt;_options[&apos;generateFiles&apos;] === false &amp;amp;&amp;amp; class_exists($this-&amp;gt;_options[&apos;className&apos;])) {
        $this-&amp;gt;generateClassFromTable($this-&amp;gt;_table); //Don&apos;t generate the class more than once ever
      }
      
      $this-&amp;gt;buildChildDefinitions();

      $this-&amp;gt;_table-&amp;gt;initIdentifier();
    }
  }
}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt; </comment>
                    <comment id="16003" author="jsiponen" created="Thu, 16 Jun 2011 20:28:21 +0000"  >&lt;p&gt;Failing test case attached&lt;/p&gt;</comment>
                    <comment id="18060" author="co3k" created="Fri, 8 Jun 2012 07:53:37 +0000"  >&lt;p&gt;Good job, Joe Siponen! Thanks for your nice patch!&lt;/p&gt;

&lt;p&gt;I can&apos;t understand why the Doctrine team discontinued maintenance of Doctrine 1 without any fixes for some serious issues like this problem...&lt;/p&gt;

&lt;p&gt;Joe, would you send your patch by pull-request in GitHub? They might notice this problem and try to fix in official repository by your request. If you cannnot, I will do it as your proxy. (Of course I&apos;m going to describe your credit)&lt;/p&gt;</comment>
                    <comment id="18626" author="co3k" created="Tue, 11 Sep 2012 13:16:23 +0000"  >&lt;p&gt;I&apos;ve tested Joe Siponen&apos;s patch, it would be good in a situation of single connection, but it doesn&apos;t work in multiple connections.&lt;/p&gt;

&lt;p&gt;So I modified your patch to fit my needs. I&apos;m testing my arranged patch and I want to publish it ASAP...&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                    <attachment id="11015" name="DC373TestCase.php" size="6100" author="jsiponen" created="Thu, 16 Jun 2011 20:28:21 +0000" />
                </attachments>
            <subtasks>
        </subtasks>
        </item>
</channel>
</rss>