• <small id='iuLiV'></small><noframes id='iuLiV'>

    <tfoot id='iuLiV'></tfoot>

    1. <i id='iuLiV'><tr id='iuLiV'><dt id='iuLiV'><q id='iuLiV'><span id='iuLiV'><b id='iuLiV'><form id='iuLiV'><ins id='iuLiV'></ins><ul id='iuLiV'></ul><sub id='iuLiV'></sub></form><legend id='iuLiV'></legend><bdo id='iuLiV'><pre id='iuLiV'><center id='iuLiV'></center></pre></bdo></b><th id='iuLiV'></th></span></q></dt></tr></i><div id='iuLiV'><tfoot id='iuLiV'></tfoot><dl id='iuLiV'><fieldset id='iuLiV'></fieldset></dl></div>

        <bdo id='iuLiV'></bdo><ul id='iuLiV'></ul>
      1. <legend id='iuLiV'><style id='iuLiV'><dir id='iuLiV'><q id='iuLiV'></q></dir></style></legend>

        教义和未更新的关系

        时间:2024-08-10
        <tfoot id='3zgSg'></tfoot>
        <i id='3zgSg'><tr id='3zgSg'><dt id='3zgSg'><q id='3zgSg'><span id='3zgSg'><b id='3zgSg'><form id='3zgSg'><ins id='3zgSg'></ins><ul id='3zgSg'></ul><sub id='3zgSg'></sub></form><legend id='3zgSg'></legend><bdo id='3zgSg'><pre id='3zgSg'><center id='3zgSg'></center></pre></bdo></b><th id='3zgSg'></th></span></q></dt></tr></i><div id='3zgSg'><tfoot id='3zgSg'></tfoot><dl id='3zgSg'><fieldset id='3zgSg'></fieldset></dl></div>

        1. <legend id='3zgSg'><style id='3zgSg'><dir id='3zgSg'><q id='3zgSg'></q></dir></style></legend>
        2. <small id='3zgSg'></small><noframes id='3zgSg'>

            <tbody id='3zgSg'></tbody>
            <bdo id='3zgSg'></bdo><ul id='3zgSg'></ul>

                  本文介绍了教义和未更新的关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在 Doctrine (1.2.4) 中看到了意想不到的缓存效果.

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

                  我有几个由以下 YAML 定义的相关表(删除了示例中未使用的几个附加字段).只是从学生到学校的简单的一对多关系.

                  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
                  

                  我可以创建一个简单的 Doctrine (1.2.4) 查询来找回一个学生

                  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();
                  

                  然后用

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

                  我现在修改 school_id(导致关系),如下:

                  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(); }
                  

                  (我已经设置了数据库,以便提供另一个有效的学校 ID).

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

                  如果我现在要立即尝试访问该关系,我将获得旧学校的名称.我明白这一点 - 这是因为我没有调用 refreshRelated().我发现意外的是,如果我立即进行另一个查询,复制第一个查询

                  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();
                  

                  得到结果

                  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?

                  推荐答案

                  Doctrine 对关系使用一点缓存:你的 Student->School 被存储到一个 Student 属性,并且您的 Student->school_id 也在另一个属性中.

                  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.

                  当您更改 Student->school_id 时,数据库会被查询,并且 Student->school_id 会更改,但 Student->学校 不会,因为再水化这个对象可能会占用 CPU/内存.

                  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 提供 一些刷新关系的方法,但使用它是开发人员的责任.

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

                  例子:

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

                  但是还有另一个缓存.Doctrine 将所有水合对象保存在内存中,以限制请求数.因此,当您再次查询您的学生时,您会发现您的 Student->School 并没有改变.

                  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.

                  这篇关于教义和未更新的关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Doctrine 2 如何在不调用实体构造函数的情况下检索实体? 下一篇:Doctrine - OneToMany 关系,所有结果行不获取对象

                  相关文章

                • <i id='ysDna'><tr id='ysDna'><dt id='ysDna'><q id='ysDna'><span id='ysDna'><b id='ysDna'><form id='ysDna'><ins id='ysDna'></ins><ul id='ysDna'></ul><sub id='ysDna'></sub></form><legend id='ysDna'></legend><bdo id='ysDna'><pre id='ysDna'><center id='ysDna'></center></pre></bdo></b><th id='ysDna'></th></span></q></dt></tr></i><div id='ysDna'><tfoot id='ysDna'></tfoot><dl id='ysDna'><fieldset id='ysDna'></fieldset></dl></div>
                    <bdo id='ysDna'></bdo><ul id='ysDna'></ul>

                • <legend id='ysDna'><style id='ysDna'><dir id='ysDna'><q id='ysDna'></q></dir></style></legend><tfoot id='ysDna'></tfoot>
                • <small id='ysDna'></small><noframes id='ysDna'>