dongshuxi3105 2012-01-04 17:32
浏览 43
已采纳

使用Propel强制数据库刷新

Here is an example of my tables

<table name="user">
  <column name="name" type="varchar" size="255" required="true" />
</table>

<table name="environment">
  <column name="user_id" type="integer" size="11" required="true" />
  <column name="insertion_time" type="timestamp" required="true" phpName="InsertionTime" />

  <foreign-key foreignTable="user" phpName="User">
    <reference local="user_id" foreign="id"/>
  </foreign-key>
</table>

I want to insert some environment linked with their user.

function insertEnvironment($id) {
    $user = findUser($id);

    $env = new Environment();
    $env->setUser($user);
    $env->setInsertionTime(new DateTime());

    $env->save();
}

function findUser($id) {
    $user = UserQuery::create()->filterByUserId($id)->findOneOrCreate();
    return $user;
}

I can insert more than one environment on the same page but I don't want to recreate the user if it already exists.

Right now, it creates one user each time I insert an environment (during the same page execution, afterwards it works as expected).

How can I force the insertion of the user so that the next time I want to access it it already exists?

Is there another way to achieve this without forcing a "flush" ? I don't want to keep track of the users by hand.

Edit: I changed the way I create the user (code above edited), but it does not help.

  • 写回答

2条回答 默认 最新

  • dongtang6718 2012-01-17 19:06
    关注

    I found a workaround, which is to disable the pooling.

    Propel::disableInstancePooling();
    

    To add in the setup.php file. But it then disable the feature completely, which drains performances down.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集