douweibiao8471 2010-06-05 09:10
浏览 46
已采纳

更新时奇怪的学说行为

I have a simple table like following:

class SnookerCurrentInfo extends Doctrine_Record 
{
  public function setTableDefinition() 
  {
    $this->hasColumn('current_frame_id', 'integer', 4, array('notnull' => 'false'));
    $this->hasColumn('current_player_id', 'integer', 4, array('notnull' => 'false'));
    $this->hasColumn('current_score1', 'integer', 4, array('notnull' => 'false'));
    $this->hasColumn('current_score2', 'integer', 4, array('notnull' => 'false'));
  }

  public function setUp()
  {
    $this->setTableName('snooker_current_info');
  }
}

and I would like to keep only one entry in this table. So every time the value is changed I read the entry with id = 1 out and change the object and execute save. like the following:

$info = Doctrine::getTable('SnookerCurrentInfo')->find(1);

$info->current_frame_id = $jsonInfo['current_frame_id'];
$info->current_player_id = $jsonInfo['current_player_id'];
$info->current_score1 = $jsonInfo['current_score1'];
$info->current_score2 = $jsonInfo['current_score2'];

$info->save();

but the strange thing is, I try to make it clear. Let's say at first, the entry is (30, 1, 1, 0) and I switch player, so update the entry to (30, 2, 1, 0). and I switch the player back again, so the entry should be updated to (30, 1, 1, 0), but this is not affected to the database!! In the database, the entry still remains as (30, 2, 1, 0)!!!!

But if after (30, 2, 1, 0), I update the score to (30, 2, 1, 1) and then switch the player back (30, 1, 1, 1) then this is ok.

What's that? How should I deal with it?

  • 写回答

2条回答 默认 最新

  • duanchensou8685 2010-06-16 09:25
    关注

    Have you tried using update instead of the save?

    Another way that works just as a save but might be more what you are needing is

     $info->replace();
    

    instead of save();

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

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效