Doctrine 1
  1. Doctrine 1
  2. DC-29

ResultCache not working with i18n behavior

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Invalid
    • Affects Version/s: 1.2.0-ALPHA1
    • Fix Version/s: 1.2.0-ALPHA2
    • Component/s: Caching
    • Labels:
      None
    • Environment:
      ubuntu 8.04 apache2 php5 with symfony

      Description

      Tested with Doctrine_Cache_APC and Doctrine_Cache_Db with SQLite.

      • The model:
      Article:
        actAs:
          Timestampable:
          Sluggable:
            fields:   [date, title]
          I18n:
            fields:       [title, content]
            actAs:
              Sluggable:
                fields:   [title]
                uniqueBy: [lang, title]
        columns:
          title:          string(255)
          date:           date
          content:        clob
      
      • The symfony code:
      frontendConfiguration.class.php
      public function configureDoctrine(Doctrine_Manager $manager)
      {
        if (sfConfig::get('sf_cache') == true)
        {
          $cacheDriver = new Doctrine_Cache_Apc();
          
          $manager->setAttribute(Doctrine::ATTR_QUERY_CACHE, $cacheDriver);
          $manager->setAttribute(
            Doctrine::ATTR_QUERY_CACHE_LIFESPAN,
            sfConfig::get('app_cache_lifetime', 86000)
          );
          $manager->setAttribute(Doctrine::ATTR_RESULT_CACHE, $cacheDriver);
          $manager->setAttribute(
            Doctrine::ATTR_RESULT_CACHE_LIFESPAN,
            sfConfig::get('app_cache_lifetime', 86000)
          );
        }
      }
      
      ArticleTable.class.php
      public function fetchAll()
      {
        return Doctrine_Query::create()
          ->from('Article a')
          ->leftJoin('a.Translation t')
          ->orderby('a.date DESC')
          ->useQueryCache()->useResultCache()
          ->execute();
      }
      
      • The Result:

      500 | Internal Server Error | Doctrine_Record_UnknownPropertyException
      Unknown record property / related component "title" on "Article"

        Activity

        Hide
        Jonathan H. Wage added a comment -

        Would it be possible to have a test case included?

        Show
        Jonathan H. Wage added a comment - Would it be possible to have a test case included?
        Hide
        Jules Bernable added a comment -

        Well, i'm new to Doctrine so I wasn't able to run the test case, but I tried to write one. :-/
        Hope this helps...

        Show
        Jules Bernable added a comment - Well, i'm new to Doctrine so I wasn't able to run the test case, but I tried to write one. :-/ Hope this helps...
        Hide
        Jonathan H. Wage added a comment -

        The problem is that you define Sluggable on the root model for the fields named title and date. But you said that title is to be I18n so no field exists named title since it was moved to the translation table. You could work around it by creating a getTitle() accessor proxy which gets the title from the translation.

        Show
        Jonathan H. Wage added a comment - The problem is that you define Sluggable on the root model for the fields named title and date. But you said that title is to be I18n so no field exists named title since it was moved to the translation table. You could work around it by creating a getTitle() accessor proxy which gets the title from the translation.
        Hide
        Jules Bernable added a comment - - edited

        Yes, but the sfDoctrineRecordI18nFilter class is supposed to handle this for me,
        and the fact is that it works fine excepted when the Result_Cache is enabled.
        Should I file a bug in the symfony trac then ?

        symfony/lib/plugins/sfDoctrinePlugin/lib/record/sfDoctrineRecordI18nFilte.class.php
        /**
         * sfDoctrineRecordI18nFilter implements access to the translated properties for
         * the current culture from the internationalized model.
         *
         * @package    symfony
         * @subpackage doctrine
         * @author     Jonathan H. Wage <jonwage@gmail.com>
         * @version    SVN: $Id: sfDoctrineRecordI18nFilter.class.php 11878 2008-09-30 20:14:40Z Jonathan.Wage $
         */
        class sfDoctrineRecordI18nFilter extends Doctrine_Record_Filter
        {
          public function init()
          {
          }
        
          /**
           * Implementation of filterSet() to call set on Translation relationship to allow
           * access to I18n properties from the main object.
           *
           * @param Doctrine_Record $record
           * @param string $name Name of the property
           * @param string $value Value of the property
           * @return void
           */
          public function filterSet(Doctrine_Record $record, $name, $value)
          {
            return $record['Translation'][sfDoctrineRecord::getDefaultCulture()][$name] = $value;
          }
        
          /**
           * Implementation of filterGet() to call get on Translation relationship to allow
           * access to I18n properties from the main object.
           *
           * @param Doctrine_Record $record
           * @param string $name Name of the property
           * @param string $value Value of the property
           * @return void
           */
          public function filterGet(Doctrine_Record $record, $name)
          {
            $culture = sfDoctrineRecord::getDefaultCulture();
            if (isset($record['Translation'][$culture]))
            {
              return $record['Translation'][$culture][$name];
            } else {
              $defaultCulture = sfConfig::get('sf_default_culture');
              return $record['Translation'][$defaultCulture][$name];
            }
          }
        }
        
        Show
        Jules Bernable added a comment - - edited Yes, but the sfDoctrineRecordI18nFilter class is supposed to handle this for me, and the fact is that it works fine excepted when the Result_Cache is enabled. Should I file a bug in the symfony trac then ? symfony/lib/plugins/sfDoctrinePlugin/lib/record/sfDoctrineRecordI18nFilte.class.php /** * sfDoctrineRecordI18nFilter implements access to the translated properties for * the current culture from the internationalized model. * * @ package symfony * @subpackage doctrine * @author Jonathan H. Wage <jonwage@gmail.com> * @version SVN: $Id: sfDoctrineRecordI18nFilter.class.php 11878 2008-09-30 20:14:40Z Jonathan.Wage $ */ class sfDoctrineRecordI18nFilter extends Doctrine_Record_Filter { public function init() { } /** * Implementation of filterSet() to call set on Translation relationship to allow * access to I18n properties from the main object. * * @param Doctrine_Record $record * @param string $name Name of the property * @param string $value Value of the property * @ return void */ public function filterSet(Doctrine_Record $record, $name, $value) { return $record['Translation'][sfDoctrineRecord::getDefaultCulture()][$name] = $value; } /** * Implementation of filterGet() to call get on Translation relationship to allow * access to I18n properties from the main object. * * @param Doctrine_Record $record * @param string $name Name of the property * @param string $value Value of the property * @ return void */ public function filterGet(Doctrine_Record $record, $name) { $culture = sfDoctrineRecord::getDefaultCulture(); if (isset($record['Translation'][$culture])) { return $record['Translation'][$culture][$name]; } else { $defaultCulture = sfConfig::get('sf_default_culture'); return $record['Translation'][$defaultCulture][$name]; } } }
        Hide
        Jonathan H. Wage added a comment -

        Ahhh. I see. I think this could be a problem with serializing and unserializing and the attached filters are not being maintained when unserialized. Not sure, i will have to have a look.

        Show
        Jonathan H. Wage added a comment - Ahhh. I see. I think this could be a problem with serializing and unserializing and the attached filters are not being maintained when unserialized. Not sure, i will have to have a look.
        Hide
        Jules Bernable added a comment -
        Show
        Jules Bernable added a comment - linked ... http://trac.symfony-project.org/ticket/7220

          People

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

            Dates

            • Created:
              Updated:
              Resolved: