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 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?