tags:

views:

25

answers:

1

Hi, guys,

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?

Thanks for a lot helping, really urgent!!

A: 

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

DrColossos
Thanks, DrColossos.I've tried update and replace, they all acted as the same as save.I thought save also does update if it is the save object, isn't it?
larryzhao