Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6053447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:02:28+00:00 2026-05-23T08:02:28+00:00

I am seeing an unexpected caching effect in Doctrine (1.2.4). I have a couple

  • 0

I am seeing an unexpected caching effect in Doctrine (1.2.4).

I have a couple of related tables defined by the following YAML (several additional fields not used in the example removed). Just a simple 1-Many relationship from students to schools.

School:
  tableName: tblschool
  columns:
    sch_id:
      name: sch_id as id
      primary: true
      autoincrement: true
      type: integer(4)
    sch_name:
      name: sch_name as name
      type: string(50)
Student:
  tableName: tblstudent
  columns:
    stu_id:
      name: stu_id as id
      primary: true
      autoincrement: true
      type: integer(4)
    stu_sch_id:
      name: stu_sch_id as school_id
      type: integer(4)
  relations:
    School:
      local: school_id
      foreign: id
      foreignAlias: Students

I can create a simple Doctrine (1.2.4) query to get back a student with

  $result1 = Doctrine_Query::create()
           ->from('Student s')
           ->where('s.id = 1')
           ->execute();

and then extract out the corresponding school name with

foreach ($result1 as $result) { $ans[] = $result->School["name"]; }

I now modify the school_id (that causes the relationship) by following this with:

foreach ($result1 as $result) 
   { $result["school_id"] = 1 - $result["school_id"]; $result->save(); }

(I have set up the DB so that this gives another valid school ID).

If I were to now, immediately, try to access the relationship I will get the old school’s name. I understand this – it is because I’ve not called refreshRelated(). What I find unexpected is that if I immediately make another query duplicating the first

  $result2 = Doctrine_Query::create()
           ->from('Student s')
           ->where('s.id = 1')
           ->execute();

and get its result

foreach ($result2 as $result) { $ans[] = $result->School["name"]; }

when I examine the contents of my array I find that, in both cases, I have the same school name. In other words, even though I’ve done a second query and am looking at the result of the query the relationship is not refreshed.

The data in the database is fine and consistent; i.e. appropriate students and schools exist. E.g. running the above sequence a second time – in a different program execution – uses the other school name (although again duplicated).

Where is this caching coming from?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:02:29+00:00Added an answer on May 23, 2026 at 8:02 am

    Doctrine use a little caching on the relations : your Student->School is stored into a Student attribute, and your Student->school_id too, in another attribute.

    When you change your Student->school_id, the database get queryied, and the Student->school_id change, but the Student->School doesn’t, as rehydrating this object might be CPU/memory expansive.

    Doctrine provide some method to refresh the relations, but it’s the developper’s responsability to use it.

    Example :

    $student->refreshRelated('School'); //refreshes only the School relation
    $student->refreshRelated(); //refreshes every relation of the $student
    

    But there’s another caching. Doctrine keeps all the hydrated object in memory, in order to limit the request number. So when you query again for your student, you find that your Student->School hasn’t changed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to integrate yaml-cpp into a project, but I'm seeing some unexpected errors
I have spring security with https settings. I'm seeing an unexpected behavior when trying
I'm seeing some unexpected behavior in Grails' createCriteria. I have a domain class that
I have the following regular expresssion /\<oauth_token\>([^\<]*)\<\/oauth_token\>/ I am seeing jslint violations for unescaped
Seeing some unexpected behavior with Python tonight. Why is the following printing out 'not
Seeing various locking related question and (almost) always finding the 'loop because of spurious
Seeing some strange things; help is being solicited. I have a query, like so:
I have been seeing this a lot lately and I am unable to find
I'm seeing a behaviour in Firefox which seems to me unexpected. This is not
I have the following code, and it's giving me a parse error when run.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.